Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull CPU hotplug updates from Thomas Gleixner:
"Yet another batch of cpu hotplug core updates and conversions:

- Provide core infrastructure for multi instance drivers so the
drivers do not have to keep custom lists.

- Convert custom lists to the new infrastructure. The block-mq custom
list conversion comes through the block tree and makes the diffstat
tip over to more lines removed than added.

- Handle unbalanced hotplug enable/disable calls more gracefully.

- Remove the obsolete CPU_STARTING/DYING notifier support.

- Convert another batch of notifier users.

The relayfs changes which conflicted with the conversion have been
shipped to me by Andrew.

The remaining lot is targeted for 4.10 so that we finally can remove
the rest of the notifiers"

* 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (46 commits)
cpufreq: Fix up conversion to hotplug state machine
blk/mq: Reserve hotplug states for block multiqueue
x86/apic/uv: Convert to hotplug state machine
s390/mm/pfault: Convert to hotplug state machine
mips/loongson/smp: Convert to hotplug state machine
mips/octeon/smp: Convert to hotplug state machine
fault-injection/cpu: Convert to hotplug state machine
padata: Convert to hotplug state machine
cpufreq: Convert to hotplug state machine
ACPI/processor: Convert to hotplug state machine
virtio scsi: Convert to hotplug state machine
oprofile/timer: Convert to hotplug state machine
block/softirq: Convert to hotplug state machine
lib/irq_poll: Convert to hotplug state machine
x86/microcode: Convert to hotplug state machine
sh/SH-X3 SMP: Convert to hotplug state machine
ia64/mca: Convert to hotplug state machine
ARM/OMAP/wakeupgen: Convert to hotplug state machine
ARM/shmobile: Convert to hotplug state machine
arm64/FP/SIMD: Convert to hotplug state machine
...

+1461 -1384
+13 -22
arch/arm/mach-omap2/omap-wakeupgen.c
··· 322 322 #endif 323 323 324 324 #ifdef CONFIG_HOTPLUG_CPU 325 - static int irq_cpu_hotplug_notify(struct notifier_block *self, 326 - unsigned long action, void *hcpu) 325 + static int omap_wakeupgen_cpu_online(unsigned int cpu) 327 326 { 328 - unsigned int cpu = (unsigned int)hcpu; 329 - 330 - /* 331 - * Corresponding FROZEN transitions do not have to be handled, 332 - * they are handled by at a higher level 333 - * (drivers/cpuidle/coupled.c). 334 - */ 335 - switch (action) { 336 - case CPU_ONLINE: 337 - wakeupgen_irqmask_all(cpu, 0); 338 - break; 339 - case CPU_DEAD: 340 - wakeupgen_irqmask_all(cpu, 1); 341 - break; 342 - } 343 - return NOTIFY_OK; 327 + wakeupgen_irqmask_all(cpu, 0); 328 + return 0; 344 329 } 345 330 346 - static struct notifier_block irq_hotplug_notifier = { 347 - .notifier_call = irq_cpu_hotplug_notify, 348 - }; 331 + static int omap_wakeupgen_cpu_dead(unsigned int cpu) 332 + { 333 + wakeupgen_irqmask_all(cpu, 1); 334 + return 0; 335 + } 349 336 350 337 static void __init irq_hotplug_init(void) 351 338 { 352 - register_hotcpu_notifier(&irq_hotplug_notifier); 339 + cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "arm/omap-wake:online", 340 + omap_wakeupgen_cpu_online, NULL); 341 + cpuhp_setup_state_nocalls(CPUHP_ARM_OMAP_WAKE_DEAD, 342 + "arm/omap-wake:dead", NULL, 343 + omap_wakeupgen_cpu_dead); 353 344 } 354 345 #else 355 346 static void __init irq_hotplug_init(void)
+8 -18
arch/arm/mach-shmobile/platsmp-scu.c
··· 21 21 static phys_addr_t shmobile_scu_base_phys; 22 22 static void __iomem *shmobile_scu_base; 23 23 24 - static int shmobile_smp_scu_notifier_call(struct notifier_block *nfb, 25 - unsigned long action, void *hcpu) 24 + static int shmobile_scu_cpu_prepare(unsigned int cpu) 26 25 { 27 - unsigned int cpu = (long)hcpu; 28 - 29 - switch (action) { 30 - case CPU_UP_PREPARE: 31 - /* For this particular CPU register SCU SMP boot vector */ 32 - shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu), 33 - shmobile_scu_base_phys); 34 - break; 35 - }; 36 - 37 - return NOTIFY_OK; 26 + /* For this particular CPU register SCU SMP boot vector */ 27 + shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu), 28 + shmobile_scu_base_phys); 29 + return 0; 38 30 } 39 - 40 - static struct notifier_block shmobile_smp_scu_notifier = { 41 - .notifier_call = shmobile_smp_scu_notifier_call, 42 - }; 43 31 44 32 void __init shmobile_smp_scu_prepare_cpus(phys_addr_t scu_base_phys, 45 33 unsigned int max_cpus) ··· 42 54 scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL); 43 55 44 56 /* Use CPU notifier for reset vector control */ 45 - register_cpu_notifier(&shmobile_smp_scu_notifier); 57 + cpuhp_setup_state_nocalls(CPUHP_ARM_SHMOBILE_SCU_PREPARE, 58 + "arm/shmobile-scu:prepare", 59 + shmobile_scu_cpu_prepare, NULL); 46 60 } 47 61 48 62 #ifdef CONFIG_HOTPLUG_CPU
+5 -17
arch/arm64/kernel/fpsimd.c
··· 299 299 #endif /* CONFIG_CPU_PM */ 300 300 301 301 #ifdef CONFIG_HOTPLUG_CPU 302 - static int fpsimd_cpu_hotplug_notifier(struct notifier_block *nfb, 303 - unsigned long action, 304 - void *hcpu) 302 + static int fpsimd_cpu_dead(unsigned int cpu) 305 303 { 306 - unsigned int cpu = (long)hcpu; 307 - 308 - switch (action) { 309 - case CPU_DEAD: 310 - case CPU_DEAD_FROZEN: 311 - per_cpu(fpsimd_last_state, cpu) = NULL; 312 - break; 313 - } 314 - return NOTIFY_OK; 304 + per_cpu(fpsimd_last_state, cpu) = NULL; 305 + return 0; 315 306 } 316 - 317 - static struct notifier_block fpsimd_cpu_hotplug_notifier_block = { 318 - .notifier_call = fpsimd_cpu_hotplug_notifier, 319 - }; 320 307 321 308 static inline void fpsimd_hotplug_init(void) 322 309 { 323 - register_cpu_notifier(&fpsimd_cpu_hotplug_notifier_block); 310 + cpuhp_setup_state_nocalls(CPUHP_ARM64_FPSIMD_DEAD, "arm64/fpsimd:dead", 311 + NULL, fpsimd_cpu_dead); 324 312 } 325 313 326 314 #else
+4 -22
arch/ia64/kernel/mca.c
··· 1890 1890 PAGE_KERNEL))); 1891 1891 } 1892 1892 1893 - static void ia64_mca_cmc_vector_adjust(void *dummy) 1893 + static int ia64_mca_cpu_online(unsigned int cpu) 1894 1894 { 1895 1895 unsigned long flags; 1896 1896 ··· 1898 1898 if (!cmc_polling_enabled) 1899 1899 ia64_mca_cmc_vector_enable(NULL); 1900 1900 local_irq_restore(flags); 1901 + return 0; 1901 1902 } 1902 - 1903 - static int mca_cpu_callback(struct notifier_block *nfb, 1904 - unsigned long action, 1905 - void *hcpu) 1906 - { 1907 - switch (action) { 1908 - case CPU_ONLINE: 1909 - case CPU_ONLINE_FROZEN: 1910 - ia64_mca_cmc_vector_adjust(NULL); 1911 - break; 1912 - } 1913 - return NOTIFY_OK; 1914 - } 1915 - 1916 - static struct notifier_block mca_cpu_notifier = { 1917 - .notifier_call = mca_cpu_callback 1918 - }; 1919 1903 1920 1904 /* 1921 1905 * ia64_mca_init ··· 2095 2111 if (!mca_init) 2096 2112 return 0; 2097 2113 2098 - register_hotcpu_notifier(&mca_cpu_notifier); 2099 - 2100 2114 /* Setup the CMCI/P vector and handler */ 2101 2115 setup_timer(&cmc_poll_timer, ia64_mca_cmc_poll, 0UL); 2102 2116 2103 2117 /* Unmask/enable the vector */ 2104 2118 cmc_polling_enabled = 0; 2105 - schedule_work(&cmc_enable_work); 2106 - 2119 + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "ia64/mca:online", 2120 + ia64_mca_cpu_online, NULL); 2107 2121 IA64_MCA_DEBUG("%s: CMCI/P setup and enabled.\n", __func__); 2108 2122 2109 2123 #ifdef CONFIG_ACPI
+3 -21
arch/mips/cavium-octeon/smp.c
··· 380 380 return 0; 381 381 } 382 382 383 - static int octeon_cpu_callback(struct notifier_block *nfb, 384 - unsigned long action, void *hcpu) 385 - { 386 - unsigned int cpu = (unsigned long)hcpu; 387 - 388 - switch (action & ~CPU_TASKS_FROZEN) { 389 - case CPU_UP_PREPARE: 390 - octeon_update_boot_vector(cpu); 391 - break; 392 - case CPU_ONLINE: 393 - pr_info("Cpu %d online\n", cpu); 394 - break; 395 - case CPU_DEAD: 396 - break; 397 - } 398 - 399 - return NOTIFY_OK; 400 - } 401 - 402 383 static int register_cavium_notifier(void) 403 384 { 404 - hotcpu_notifier(octeon_cpu_callback, 0); 405 - return 0; 385 + return cpuhp_setup_state_nocalls(CPUHP_MIPS_SOC_PREPARE, 386 + "mips/cavium:prepare", 387 + octeon_update_boot_vector, NULL); 406 388 } 407 389 late_initcall(register_cavium_notifier); 408 390
+8 -26
arch/mips/loongson64/loongson-3/smp.c
··· 677 677 play_dead_at_ckseg1(state_addr); 678 678 } 679 679 680 - void loongson3_disable_clock(int cpu) 680 + static int loongson3_disable_clock(unsigned int cpu) 681 681 { 682 682 uint64_t core_id = cpu_data[cpu].core; 683 683 uint64_t package_id = cpu_data[cpu].package; ··· 688 688 if (!(loongson_sysconf.workarounds & WORKAROUND_CPUHOTPLUG)) 689 689 LOONGSON_FREQCTRL(package_id) &= ~(1 << (core_id * 4 + 3)); 690 690 } 691 + return 0; 691 692 } 692 693 693 - void loongson3_enable_clock(int cpu) 694 + static int loongson3_enable_clock(unsigned int cpu) 694 695 { 695 696 uint64_t core_id = cpu_data[cpu].core; 696 697 uint64_t package_id = cpu_data[cpu].package; ··· 702 701 if (!(loongson_sysconf.workarounds & WORKAROUND_CPUHOTPLUG)) 703 702 LOONGSON_FREQCTRL(package_id) |= 1 << (core_id * 4 + 3); 704 703 } 705 - } 706 - 707 - #define CPU_POST_DEAD_FROZEN (CPU_POST_DEAD | CPU_TASKS_FROZEN) 708 - static int loongson3_cpu_callback(struct notifier_block *nfb, 709 - unsigned long action, void *hcpu) 710 - { 711 - unsigned int cpu = (unsigned long)hcpu; 712 - 713 - switch (action) { 714 - case CPU_POST_DEAD: 715 - case CPU_POST_DEAD_FROZEN: 716 - pr_info("Disable clock for CPU#%d\n", cpu); 717 - loongson3_disable_clock(cpu); 718 - break; 719 - case CPU_UP_PREPARE: 720 - case CPU_UP_PREPARE_FROZEN: 721 - pr_info("Enable clock for CPU#%d\n", cpu); 722 - loongson3_enable_clock(cpu); 723 - break; 724 - } 725 - 726 - return NOTIFY_OK; 704 + return 0; 727 705 } 728 706 729 707 static int register_loongson3_notifier(void) 730 708 { 731 - hotcpu_notifier(loongson3_cpu_callback, 0); 732 - return 0; 709 + return cpuhp_setup_state_nocalls(CPUHP_MIPS_SOC_PREPARE, 710 + "mips/loongson:prepare", 711 + loongson3_enable_clock, 712 + loongson3_disable_clock); 733 713 } 734 714 early_initcall(register_loongson3_notifier); 735 715
+23 -31
arch/powerpc/mm/mmu_context_nohash.c
··· 369 369 } 370 370 371 371 #ifdef CONFIG_SMP 372 - 373 - static int mmu_context_cpu_notify(struct notifier_block *self, 374 - unsigned long action, void *hcpu) 372 + static int mmu_ctx_cpu_prepare(unsigned int cpu) 375 373 { 376 - unsigned int cpu = (unsigned int)(long)hcpu; 377 - 378 374 /* We don't touch CPU 0 map, it's allocated at aboot and kept 379 375 * around forever 380 376 */ 381 377 if (cpu == boot_cpuid) 382 - return NOTIFY_OK; 378 + return 0; 383 379 384 - switch (action) { 385 - case CPU_UP_PREPARE: 386 - case CPU_UP_PREPARE_FROZEN: 387 - pr_devel("MMU: Allocating stale context map for CPU %d\n", cpu); 388 - stale_map[cpu] = kzalloc(CTX_MAP_SIZE, GFP_KERNEL); 389 - break; 390 - #ifdef CONFIG_HOTPLUG_CPU 391 - case CPU_UP_CANCELED: 392 - case CPU_UP_CANCELED_FROZEN: 393 - case CPU_DEAD: 394 - case CPU_DEAD_FROZEN: 395 - pr_devel("MMU: Freeing stale context map for CPU %d\n", cpu); 396 - kfree(stale_map[cpu]); 397 - stale_map[cpu] = NULL; 398 - 399 - /* We also clear the cpu_vm_mask bits of CPUs going away */ 400 - clear_tasks_mm_cpumask(cpu); 401 - break; 402 - #endif /* CONFIG_HOTPLUG_CPU */ 403 - } 404 - return NOTIFY_OK; 380 + pr_devel("MMU: Allocating stale context map for CPU %d\n", cpu); 381 + stale_map[cpu] = kzalloc(CTX_MAP_SIZE, GFP_KERNEL); 382 + return 0; 405 383 } 406 384 407 - static struct notifier_block mmu_context_cpu_nb = { 408 - .notifier_call = mmu_context_cpu_notify, 409 - }; 385 + static int mmu_ctx_cpu_dead(unsigned int cpu) 386 + { 387 + #ifdef CONFIG_HOTPLUG_CPU 388 + if (cpu == boot_cpuid) 389 + return 0; 390 + 391 + pr_devel("MMU: Freeing stale context map for CPU %d\n", cpu); 392 + kfree(stale_map[cpu]); 393 + stale_map[cpu] = NULL; 394 + 395 + /* We also clear the cpu_vm_mask bits of CPUs going away */ 396 + clear_tasks_mm_cpumask(cpu); 397 + #endif 398 + return 0; 399 + } 410 400 411 401 #endif /* CONFIG_SMP */ 412 402 ··· 459 469 #else 460 470 stale_map[boot_cpuid] = memblock_virt_alloc(CTX_MAP_SIZE, 0); 461 471 462 - register_cpu_notifier(&mmu_context_cpu_nb); 472 + cpuhp_setup_state_nocalls(CPUHP_POWERPC_MMU_CTX_PREPARE, 473 + "powerpc/mmu/ctx:prepare", 474 + mmu_ctx_cpu_prepare, mmu_ctx_cpu_dead); 463 475 #endif 464 476 465 477 printk(KERN_INFO
+25 -25
arch/powerpc/platforms/powermac/smp.c
··· 852 852 853 853 #ifdef CONFIG_PPC64 854 854 #ifdef CONFIG_HOTPLUG_CPU 855 - static int smp_core99_cpu_notify(struct notifier_block *self, 856 - unsigned long action, void *hcpu) 855 + static unsigned int smp_core99_host_open; 856 + 857 + static int smp_core99_cpu_prepare(unsigned int cpu) 857 858 { 858 859 int rc; 859 860 860 - switch(action & ~CPU_TASKS_FROZEN) { 861 - case CPU_UP_PREPARE: 862 - /* Open i2c bus if it was used for tb sync */ 863 - if (pmac_tb_clock_chip_host) { 864 - rc = pmac_i2c_open(pmac_tb_clock_chip_host, 1); 865 - if (rc) { 866 - pr_err("Failed to open i2c bus for time sync\n"); 867 - return notifier_from_errno(rc); 868 - } 861 + /* Open i2c bus if it was used for tb sync */ 862 + if (pmac_tb_clock_chip_host && !smp_core99_host_open) { 863 + rc = pmac_i2c_open(pmac_tb_clock_chip_host, 1); 864 + if (rc) { 865 + pr_err("Failed to open i2c bus for time sync\n"); 866 + return notifier_from_errno(rc); 869 867 } 870 - break; 871 - case CPU_ONLINE: 872 - case CPU_UP_CANCELED: 873 - /* Close i2c bus if it was used for tb sync */ 874 - if (pmac_tb_clock_chip_host) 875 - pmac_i2c_close(pmac_tb_clock_chip_host); 876 - break; 877 - default: 878 - break; 868 + smp_core99_host_open = 1; 879 869 } 880 - return NOTIFY_OK; 870 + return 0; 881 871 } 882 872 883 - static struct notifier_block smp_core99_cpu_nb = { 884 - .notifier_call = smp_core99_cpu_notify, 885 - }; 873 + static int smp_core99_cpu_online(unsigned int cpu) 874 + { 875 + /* Close i2c bus if it was used for tb sync */ 876 + if (pmac_tb_clock_chip_host && smp_core99_host_open) { 877 + pmac_i2c_close(pmac_tb_clock_chip_host); 878 + smp_core99_host_open = 0; 879 + } 880 + return 0; 881 + } 886 882 #endif /* CONFIG_HOTPLUG_CPU */ 887 883 888 884 static void __init smp_core99_bringup_done(void) ··· 898 902 g5_phy_disable_cpu1(); 899 903 } 900 904 #ifdef CONFIG_HOTPLUG_CPU 901 - register_cpu_notifier(&smp_core99_cpu_nb); 905 + cpuhp_setup_state_nocalls(CPUHP_POWERPC_PMAC_PREPARE, 906 + "powerpc/pmac:prepare", smp_core99_cpu_prepare, 907 + NULL); 908 + cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "powerpc/pmac:online", 909 + smp_core99_cpu_online, NULL); 902 910 #endif 903 911 904 912 if (ppc_md.progress)
+12 -18
arch/s390/mm/fault.c
··· 740 740 put_task_struct(tsk); 741 741 } 742 742 743 - static int pfault_cpu_notify(struct notifier_block *self, unsigned long action, 744 - void *hcpu) 743 + static int pfault_cpu_dead(unsigned int cpu) 745 744 { 746 745 struct thread_struct *thread, *next; 747 746 struct task_struct *tsk; 748 747 749 - switch (action & ~CPU_TASKS_FROZEN) { 750 - case CPU_DEAD: 751 - spin_lock_irq(&pfault_lock); 752 - list_for_each_entry_safe(thread, next, &pfault_list, list) { 753 - thread->pfault_wait = 0; 754 - list_del(&thread->list); 755 - tsk = container_of(thread, struct task_struct, thread); 756 - wake_up_process(tsk); 757 - put_task_struct(tsk); 758 - } 759 - spin_unlock_irq(&pfault_lock); 760 - break; 761 - default: 762 - break; 748 + spin_lock_irq(&pfault_lock); 749 + list_for_each_entry_safe(thread, next, &pfault_list, list) { 750 + thread->pfault_wait = 0; 751 + list_del(&thread->list); 752 + tsk = container_of(thread, struct task_struct, thread); 753 + wake_up_process(tsk); 754 + put_task_struct(tsk); 763 755 } 764 - return NOTIFY_OK; 756 + spin_unlock_irq(&pfault_lock); 757 + return 0; 765 758 } 766 759 767 760 static int __init pfault_irq_init(void) ··· 768 775 if (rc) 769 776 goto out_pfault; 770 777 irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL); 771 - hotcpu_notifier(pfault_cpu_notify, 0); 778 + cpuhp_setup_state_nocalls(CPUHP_S390_PFAULT_DEAD, "s390/pfault:dead", 779 + NULL, pfault_cpu_dead); 772 780 return 0; 773 781 774 782 out_pfault:
+5 -21
arch/sh/kernel/cpu/sh4a/smp-shx3.c
··· 122 122 __raw_writel(STBCR_RESET, STBCR_REG(cpu)); 123 123 } 124 124 125 - static int 126 - shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) 125 + static int shx3_cpu_prepare(unsigned int cpu) 127 126 { 128 - unsigned int cpu = (unsigned int)hcpu; 129 - 130 - switch (action) { 131 - case CPU_UP_PREPARE: 132 - shx3_update_boot_vector(cpu); 133 - break; 134 - case CPU_ONLINE: 135 - pr_info("CPU %u is now online\n", cpu); 136 - break; 137 - case CPU_DEAD: 138 - break; 139 - } 140 - 141 - return NOTIFY_OK; 127 + shx3_update_boot_vector(cpu); 128 + return 0; 142 129 } 143 - 144 - static struct notifier_block shx3_cpu_notifier = { 145 - .notifier_call = shx3_cpu_callback, 146 - }; 147 130 148 131 static int register_shx3_cpu_notifier(void) 149 132 { 150 - register_hotcpu_notifier(&shx3_cpu_notifier); 133 + cpuhp_setup_state_nocalls(CPUHP_SH_SH3X_PREPARE, "sh/shx3:prepare", 134 + shx3_cpu_prepare, NULL); 151 135 return 0; 152 136 } 153 137 late_initcall(register_shx3_cpu_notifier);
-2
arch/sparc/kernel/smp_32.c
··· 352 352 preempt_disable(); 353 353 cpu = smp_processor_id(); 354 354 355 - /* Invoke the CPU_STARTING notifier callbacks */ 356 355 notify_cpu_starting(cpu); 357 - 358 356 arch_cpu_pre_online(arg); 359 357 360 358 /* Set the CPU in the cpu_online_mask */
+6 -25
arch/x86/kernel/apic/x2apic_uv_x.c
··· 924 924 mod_timer(timer, jiffies + SCIR_CPU_HB_INTERVAL); 925 925 } 926 926 927 - static void uv_heartbeat_enable(int cpu) 927 + static int uv_heartbeat_enable(unsigned int cpu) 928 928 { 929 929 while (!uv_cpu_scir_info(cpu)->enabled) { 930 930 struct timer_list *timer = &uv_cpu_scir_info(cpu)->timer; ··· 938 938 /* also ensure that boot cpu is enabled */ 939 939 cpu = 0; 940 940 } 941 + return 0; 941 942 } 942 943 943 944 #ifdef CONFIG_HOTPLUG_CPU 944 - static void uv_heartbeat_disable(int cpu) 945 + static int uv_heartbeat_disable(unsigned int cpu) 945 946 { 946 947 if (uv_cpu_scir_info(cpu)->enabled) { 947 948 uv_cpu_scir_info(cpu)->enabled = 0; 948 949 del_timer(&uv_cpu_scir_info(cpu)->timer); 949 950 } 950 951 uv_set_cpu_scir_bits(cpu, 0xff); 951 - } 952 - 953 - /* 954 - * cpu hotplug notifier 955 - */ 956 - static int uv_scir_cpu_notify(struct notifier_block *self, unsigned long action, 957 - void *hcpu) 958 - { 959 - long cpu = (long)hcpu; 960 - 961 - switch (action & ~CPU_TASKS_FROZEN) { 962 - case CPU_DOWN_FAILED: 963 - case CPU_ONLINE: 964 - uv_heartbeat_enable(cpu); 965 - break; 966 - case CPU_DOWN_PREPARE: 967 - uv_heartbeat_disable(cpu); 968 - break; 969 - default: 970 - break; 971 - } 972 - return NOTIFY_OK; 952 + return 0; 973 953 } 974 954 975 955 static __init void uv_scir_register_cpu_notifier(void) 976 956 { 977 - hotcpu_notifier(uv_scir_cpu_notify, 0); 957 + cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/x2apic-uvx:online", 958 + uv_heartbeat_enable, uv_heartbeat_disable); 978 959 } 979 960 980 961 #else /* !CONFIG_HOTPLUG_CPU */
+17 -35
arch/x86/kernel/cpu/microcode/core.c
··· 558 558 .resume = mc_bp_resume, 559 559 }; 560 560 561 - static int 562 - mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu) 561 + static int mc_cpu_online(unsigned int cpu) 563 562 { 564 - unsigned int cpu = (unsigned long)hcpu; 565 563 struct device *dev; 566 564 567 565 dev = get_cpu_device(cpu); 566 + microcode_update_cpu(cpu); 567 + pr_debug("CPU%d added\n", cpu); 568 568 569 - switch (action & ~CPU_TASKS_FROZEN) { 570 - case CPU_ONLINE: 571 - microcode_update_cpu(cpu); 572 - pr_debug("CPU%d added\n", cpu); 573 - /* 574 - * "break" is missing on purpose here because we want to fall 575 - * through in order to create the sysfs group. 576 - */ 569 + if (sysfs_create_group(&dev->kobj, &mc_attr_group)) 570 + pr_err("Failed to create group for CPU%d\n", cpu); 571 + return 0; 572 + } 577 573 578 - case CPU_DOWN_FAILED: 579 - if (sysfs_create_group(&dev->kobj, &mc_attr_group)) 580 - pr_err("Failed to create group for CPU%d\n", cpu); 581 - break; 574 + static int mc_cpu_down_prep(unsigned int cpu) 575 + { 576 + struct device *dev; 582 577 583 - case CPU_DOWN_PREPARE: 584 - /* Suspend is in progress, only remove the interface */ 585 - sysfs_remove_group(&dev->kobj, &mc_attr_group); 586 - pr_debug("CPU%d removed\n", cpu); 587 - break; 588 - 578 + dev = get_cpu_device(cpu); 579 + /* Suspend is in progress, only remove the interface */ 580 + sysfs_remove_group(&dev->kobj, &mc_attr_group); 581 + pr_debug("CPU%d removed\n", cpu); 589 582 /* 590 - * case CPU_DEAD: 591 - * 592 583 * When a CPU goes offline, don't free up or invalidate the copy of 593 584 * the microcode in kernel memory, so that we can reuse it when the 594 585 * CPU comes back online without unnecessarily requesting the userspace 595 586 * for it again. 596 587 */ 597 - } 598 - 599 - /* The CPU refused to come up during a system resume */ 600 - if (action == CPU_UP_CANCELED_FROZEN) 601 - microcode_fini_cpu(cpu); 602 - 603 - return NOTIFY_OK; 588 + return 0; 604 589 } 605 - 606 - static struct notifier_block mc_cpu_notifier = { 607 - .notifier_call = mc_cpu_callback, 608 - }; 609 590 610 591 static struct attribute *cpu_root_microcode_attrs[] = { 611 592 &dev_attr_reload.attr, ··· 646 665 goto out_ucode_group; 647 666 648 667 register_syscore_ops(&mc_syscore_ops); 649 - register_hotcpu_notifier(&mc_cpu_notifier); 668 + cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/microcode:online", 669 + mc_cpu_online, mc_cpu_down_prep); 650 670 651 671 pr_info("Microcode Update Driver: v" MICROCODE_VERSION 652 672 " <tigran@aivazian.fsnet.co.uk>, Peter Oruba\n");
+16 -27
arch/x86/kernel/kvm.c
··· 423 423 kvm_spinlock_init(); 424 424 } 425 425 426 - static void kvm_guest_cpu_online(void *dummy) 427 - { 428 - kvm_guest_cpu_init(); 429 - } 430 - 431 - static void kvm_guest_cpu_offline(void *dummy) 426 + static void kvm_guest_cpu_offline(void) 432 427 { 433 428 kvm_disable_steal_time(); 434 429 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) ··· 432 437 apf_task_wake_all(); 433 438 } 434 439 435 - static int kvm_cpu_notify(struct notifier_block *self, unsigned long action, 436 - void *hcpu) 440 + static int kvm_cpu_online(unsigned int cpu) 437 441 { 438 - int cpu = (unsigned long)hcpu; 439 - switch (action) { 440 - case CPU_ONLINE: 441 - case CPU_DOWN_FAILED: 442 - case CPU_ONLINE_FROZEN: 443 - smp_call_function_single(cpu, kvm_guest_cpu_online, NULL, 0); 444 - break; 445 - case CPU_DOWN_PREPARE: 446 - case CPU_DOWN_PREPARE_FROZEN: 447 - smp_call_function_single(cpu, kvm_guest_cpu_offline, NULL, 1); 448 - break; 449 - default: 450 - break; 451 - } 452 - return NOTIFY_OK; 442 + local_irq_disable(); 443 + kvm_guest_cpu_init(); 444 + local_irq_enable(); 445 + return 0; 453 446 } 454 447 455 - static struct notifier_block kvm_cpu_notifier = { 456 - .notifier_call = kvm_cpu_notify, 457 - }; 448 + static int kvm_cpu_down_prepare(unsigned int cpu) 449 + { 450 + local_irq_disable(); 451 + kvm_guest_cpu_offline(); 452 + local_irq_enable(); 453 + return 0; 454 + } 458 455 #endif 459 456 460 457 static void __init kvm_apf_trap_init(void) ··· 481 494 482 495 #ifdef CONFIG_SMP 483 496 smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu; 484 - register_cpu_notifier(&kvm_cpu_notifier); 497 + if (cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/kvm:online", 498 + kvm_cpu_online, kvm_cpu_down_prepare) < 0) 499 + pr_err("kvm_guest: Failed to install cpu hotplug callbacks\n"); 485 500 #else 486 501 kvm_guest_cpu_init(); 487 502 #endif
-11
arch/x86/kernel/smpboot.c
··· 1115 1115 1116 1116 common_cpu_up(cpu, tidle); 1117 1117 1118 - /* 1119 - * We have to walk the irq descriptors to setup the vector 1120 - * space for the cpu which comes online. Prevent irq 1121 - * alloc/free across the bringup. 1122 - */ 1123 - irq_lock_sparse(); 1124 - 1125 1118 err = do_boot_cpu(apicid, cpu, tidle); 1126 - 1127 1119 if (err) { 1128 - irq_unlock_sparse(); 1129 1120 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu); 1130 1121 return -EIO; 1131 1122 } ··· 1133 1142 cpu_relax(); 1134 1143 touch_nmi_watchdog(); 1135 1144 } 1136 - 1137 - irq_unlock_sparse(); 1138 1145 1139 1146 return 0; 1140 1147 }
+10 -17
block/blk-softirq.c
··· 78 78 } 79 79 #endif 80 80 81 - static int blk_cpu_notify(struct notifier_block *self, unsigned long action, 82 - void *hcpu) 81 + static int blk_softirq_cpu_dead(unsigned int cpu) 83 82 { 84 83 /* 85 84 * If a CPU goes away, splice its entries to the current CPU 86 85 * and trigger a run of the softirq 87 86 */ 88 - if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) { 89 - int cpu = (unsigned long) hcpu; 87 + local_irq_disable(); 88 + list_splice_init(&per_cpu(blk_cpu_done, cpu), 89 + this_cpu_ptr(&blk_cpu_done)); 90 + raise_softirq_irqoff(BLOCK_SOFTIRQ); 91 + local_irq_enable(); 90 92 91 - local_irq_disable(); 92 - list_splice_init(&per_cpu(blk_cpu_done, cpu), 93 - this_cpu_ptr(&blk_cpu_done)); 94 - raise_softirq_irqoff(BLOCK_SOFTIRQ); 95 - local_irq_enable(); 96 - } 97 - 98 - return NOTIFY_OK; 93 + return 0; 99 94 } 100 - 101 - static struct notifier_block blk_cpu_notifier = { 102 - .notifier_call = blk_cpu_notify, 103 - }; 104 95 105 96 void __blk_complete_request(struct request *req) 106 97 { ··· 171 180 INIT_LIST_HEAD(&per_cpu(blk_cpu_done, i)); 172 181 173 182 open_softirq(BLOCK_SOFTIRQ, blk_done_softirq); 174 - register_hotcpu_notifier(&blk_cpu_notifier); 183 + cpuhp_setup_state_nocalls(CPUHP_BLOCK_SOFTIRQ_DEAD, 184 + "block/softirq:dead", NULL, 185 + blk_softirq_cpu_dead); 175 186 return 0; 176 187 } 177 188 subsys_initcall(blk_softirq_init);
+46 -43
drivers/acpi/processor_driver.c
··· 110 110 111 111 static int __acpi_processor_start(struct acpi_device *device); 112 112 113 - static int acpi_cpu_soft_notify(struct notifier_block *nfb, 114 - unsigned long action, void *hcpu) 113 + static int acpi_soft_cpu_online(unsigned int cpu) 115 114 { 116 - unsigned int cpu = (unsigned long)hcpu; 117 115 struct acpi_processor *pr = per_cpu(processors, cpu); 118 116 struct acpi_device *device; 119 - action &= ~CPU_TASKS_FROZEN; 120 - 121 - switch (action) { 122 - case CPU_ONLINE: 123 - case CPU_DEAD: 124 - break; 125 - default: 126 - return NOTIFY_DONE; 127 - } 128 117 129 118 if (!pr || acpi_bus_get_device(pr->handle, &device)) 130 - return NOTIFY_DONE; 119 + return 0; 120 + /* 121 + * CPU got physically hotplugged and onlined for the first time: 122 + * Initialize missing things. 123 + */ 124 + if (pr->flags.need_hotplug_init) { 125 + int ret; 131 126 132 - if (action == CPU_ONLINE) { 133 - /* 134 - * CPU got physically hotplugged and onlined for the first time: 135 - * Initialize missing things. 136 - */ 137 - if (pr->flags.need_hotplug_init) { 138 - int ret; 139 - 140 - pr_info("Will online and init hotplugged CPU: %d\n", 141 - pr->id); 142 - pr->flags.need_hotplug_init = 0; 143 - ret = __acpi_processor_start(device); 144 - WARN(ret, "Failed to start CPU: %d\n", pr->id); 145 - } else { 146 - /* Normal CPU soft online event. */ 147 - acpi_processor_ppc_has_changed(pr, 0); 148 - acpi_processor_hotplug(pr); 149 - acpi_processor_reevaluate_tstate(pr, action); 150 - acpi_processor_tstate_has_changed(pr); 151 - } 152 - } else if (action == CPU_DEAD) { 153 - /* Invalidate flag.throttling after the CPU is offline. */ 154 - acpi_processor_reevaluate_tstate(pr, action); 127 + pr_info("Will online and init hotplugged CPU: %d\n", 128 + pr->id); 129 + pr->flags.need_hotplug_init = 0; 130 + ret = __acpi_processor_start(device); 131 + WARN(ret, "Failed to start CPU: %d\n", pr->id); 132 + } else { 133 + /* Normal CPU soft online event. */ 134 + acpi_processor_ppc_has_changed(pr, 0); 135 + acpi_processor_hotplug(pr); 136 + acpi_processor_reevaluate_tstate(pr, false); 137 + acpi_processor_tstate_has_changed(pr); 155 138 } 156 - return NOTIFY_OK; 139 + return 0; 157 140 } 158 141 159 - static struct notifier_block acpi_cpu_notifier = { 160 - .notifier_call = acpi_cpu_soft_notify, 161 - }; 142 + static int acpi_soft_cpu_dead(unsigned int cpu) 143 + { 144 + struct acpi_processor *pr = per_cpu(processors, cpu); 145 + struct acpi_device *device; 146 + 147 + if (!pr || acpi_bus_get_device(pr->handle, &device)) 148 + return 0; 149 + 150 + acpi_processor_reevaluate_tstate(pr, true); 151 + return 0; 152 + } 162 153 163 154 #ifdef CONFIG_ACPI_CPU_FREQ_PSS 164 155 static int acpi_pss_perf_init(struct acpi_processor *pr, ··· 294 303 * This is needed for the powernow-k8 driver, that works even without 295 304 * ACPI, but needs symbols from this driver 296 305 */ 297 - 306 + static enum cpuhp_state hp_online; 298 307 static int __init acpi_processor_driver_init(void) 299 308 { 300 309 int result = 0; ··· 306 315 if (result < 0) 307 316 return result; 308 317 309 - register_hotcpu_notifier(&acpi_cpu_notifier); 318 + result = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, 319 + "acpi/cpu-drv:online", 320 + acpi_soft_cpu_online, NULL); 321 + if (result < 0) 322 + goto err; 323 + hp_online = result; 324 + cpuhp_setup_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD, "acpi/cpu-drv:dead", 325 + NULL, acpi_soft_cpu_dead); 326 + 310 327 acpi_thermal_cpufreq_init(); 311 328 acpi_processor_ppc_init(); 312 329 acpi_processor_throttling_init(); 313 330 return 0; 331 + err: 332 + driver_unregister(&acpi_processor_driver); 333 + return result; 314 334 } 315 335 316 336 static void __exit acpi_processor_driver_exit(void) ··· 331 329 332 330 acpi_processor_ppc_exit(); 333 331 acpi_thermal_cpufreq_exit(); 334 - unregister_hotcpu_notifier(&acpi_cpu_notifier); 332 + cpuhp_remove_state_nocalls(hp_online); 333 + cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD); 335 334 driver_unregister(&acpi_processor_driver); 336 335 } 337 336
+2 -2
drivers/acpi/processor_throttling.c
··· 375 375 * 3. TSD domain 376 376 */ 377 377 void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, 378 - unsigned long action) 378 + bool is_dead) 379 379 { 380 380 int result = 0; 381 381 382 - if (action == CPU_DEAD) { 382 + if (is_dead) { 383 383 /* When one CPU is offline, the T-state throttling 384 384 * will be invalidated. 385 385 */
+18 -27
drivers/bus/arm-cci.c
··· 144 144 int num_cntrs; 145 145 atomic_t active_events; 146 146 struct mutex reserve_mutex; 147 - struct list_head entry; 147 + struct hlist_node node; 148 148 cpumask_t cpus; 149 149 }; 150 150 151 151 #define to_cci_pmu(c) (container_of(c, struct cci_pmu, pmu)) 152 - 153 - static DEFINE_MUTEX(cci_pmu_mutex); 154 - static LIST_HEAD(cci_pmu_list); 155 152 156 153 enum cci_models { 157 154 #ifdef CONFIG_ARM_CCI400_PMU ··· 1503 1506 return perf_pmu_register(&cci_pmu->pmu, name, -1); 1504 1507 } 1505 1508 1506 - static int cci_pmu_offline_cpu(unsigned int cpu) 1509 + static int cci_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) 1507 1510 { 1508 - struct cci_pmu *cci_pmu; 1511 + struct cci_pmu *cci_pmu = hlist_entry_safe(node, struct cci_pmu, node); 1509 1512 unsigned int target; 1510 1513 1511 - mutex_lock(&cci_pmu_mutex); 1512 - list_for_each_entry(cci_pmu, &cci_pmu_list, entry) { 1513 - if (!cpumask_test_and_clear_cpu(cpu, &cci_pmu->cpus)) 1514 - continue; 1515 - target = cpumask_any_but(cpu_online_mask, cpu); 1516 - if (target >= nr_cpu_ids) 1517 - continue; 1518 - /* 1519 - * TODO: migrate context once core races on event->ctx have 1520 - * been fixed. 1521 - */ 1522 - cpumask_set_cpu(target, &cci_pmu->cpus); 1523 - } 1524 - mutex_unlock(&cci_pmu_mutex); 1514 + if (!cpumask_test_and_clear_cpu(cpu, &cci_pmu->cpus)) 1515 + return 0; 1516 + target = cpumask_any_but(cpu_online_mask, cpu); 1517 + if (target >= nr_cpu_ids) 1518 + return 0; 1519 + /* 1520 + * TODO: migrate context once core races on event->ctx have 1521 + * been fixed. 1522 + */ 1523 + cpumask_set_cpu(target, &cci_pmu->cpus); 1525 1524 return 0; 1526 1525 } 1527 1526 ··· 1761 1768 if (ret) 1762 1769 return ret; 1763 1770 1764 - mutex_lock(&cci_pmu_mutex); 1765 - list_add(&cci_pmu->entry, &cci_pmu_list); 1766 - mutex_unlock(&cci_pmu_mutex); 1767 - 1771 + cpuhp_state_add_instance_nocalls(CPUHP_AP_PERF_ARM_CCI_ONLINE, 1772 + &cci_pmu->node); 1768 1773 pr_info("ARM %s PMU driver probed", cci_pmu->model->name); 1769 1774 return 0; 1770 1775 } ··· 1795 1804 { 1796 1805 int ret; 1797 1806 1798 - ret = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_CCI_ONLINE, 1799 - "AP_PERF_ARM_CCI_ONLINE", NULL, 1800 - cci_pmu_offline_cpu); 1807 + ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_ARM_CCI_ONLINE, 1808 + "AP_PERF_ARM_CCI_ONLINE", NULL, 1809 + cci_pmu_offline_cpu); 1801 1810 if (ret) 1802 1811 return ret; 1803 1812
+21 -33
drivers/bus/arm-ccn.c
··· 167 167 struct hrtimer hrtimer; 168 168 169 169 cpumask_t cpu; 170 - struct list_head entry; 170 + struct hlist_node node; 171 171 172 172 struct pmu pmu; 173 173 }; ··· 189 189 struct arm_ccn_dt dt; 190 190 int mn_id; 191 191 }; 192 - 193 - static DEFINE_MUTEX(arm_ccn_mutex); 194 - static LIST_HEAD(arm_ccn_list); 195 192 196 193 static int arm_ccn_node_to_xp(int node) 197 194 { ··· 1211 1214 } 1212 1215 1213 1216 1214 - static int arm_ccn_pmu_offline_cpu(unsigned int cpu) 1217 + static int arm_ccn_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) 1215 1218 { 1216 - struct arm_ccn_dt *dt; 1219 + struct arm_ccn_dt *dt = hlist_entry_safe(node, struct arm_ccn_dt, node); 1220 + struct arm_ccn *ccn = container_of(dt, struct arm_ccn, dt); 1217 1221 unsigned int target; 1218 1222 1219 - mutex_lock(&arm_ccn_mutex); 1220 - list_for_each_entry(dt, &arm_ccn_list, entry) { 1221 - struct arm_ccn *ccn = container_of(dt, struct arm_ccn, dt); 1222 - 1223 - if (!cpumask_test_and_clear_cpu(cpu, &dt->cpu)) 1224 - continue; 1225 - target = cpumask_any_but(cpu_online_mask, cpu); 1226 - if (target >= nr_cpu_ids) 1227 - continue; 1228 - perf_pmu_migrate_context(&dt->pmu, cpu, target); 1229 - cpumask_set_cpu(target, &dt->cpu); 1230 - if (ccn->irq) 1231 - WARN_ON(irq_set_affinity_hint(ccn->irq, &dt->cpu) != 0); 1232 - } 1233 - mutex_unlock(&arm_ccn_mutex); 1223 + if (!cpumask_test_and_clear_cpu(cpu, &dt->cpu)) 1224 + return 0; 1225 + target = cpumask_any_but(cpu_online_mask, cpu); 1226 + if (target >= nr_cpu_ids) 1227 + return 0; 1228 + perf_pmu_migrate_context(&dt->pmu, cpu, target); 1229 + cpumask_set_cpu(target, &dt->cpu); 1230 + if (ccn->irq) 1231 + WARN_ON(irq_set_affinity_hint(ccn->irq, &dt->cpu) != 0); 1234 1232 return 0; 1235 1233 } 1236 - 1237 1234 1238 1235 static DEFINE_IDA(arm_ccn_pmu_ida); 1239 1236 ··· 1312 1321 if (err) 1313 1322 goto error_pmu_register; 1314 1323 1315 - mutex_lock(&arm_ccn_mutex); 1316 - list_add(&ccn->dt.entry, &arm_ccn_list); 1317 - mutex_unlock(&arm_ccn_mutex); 1324 + cpuhp_state_add_instance_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE, 1325 + &ccn->dt.node); 1318 1326 return 0; 1319 1327 1320 1328 error_pmu_register: ··· 1329 1339 { 1330 1340 int i; 1331 1341 1332 - mutex_lock(&arm_ccn_mutex); 1333 - list_del(&ccn->dt.entry); 1334 - mutex_unlock(&arm_ccn_mutex); 1335 - 1342 + cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE, 1343 + &ccn->dt.node); 1336 1344 if (ccn->irq) 1337 1345 irq_set_affinity_hint(ccn->irq, NULL); 1338 1346 for (i = 0; i < ccn->num_xps; i++) ··· 1561 1573 { 1562 1574 int i, ret; 1563 1575 1564 - ret = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE, 1565 - "AP_PERF_ARM_CCN_ONLINE", NULL, 1566 - arm_ccn_pmu_offline_cpu); 1576 + ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_ARM_CCN_ONLINE, 1577 + "AP_PERF_ARM_CCN_ONLINE", NULL, 1578 + arm_ccn_pmu_offline_cpu); 1567 1579 if (ret) 1568 1580 return ret; 1569 1581 ··· 1575 1587 1576 1588 static void __exit arm_ccn_exit(void) 1577 1589 { 1578 - cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE); 1590 + cpuhp_remove_multi_state(CPUHP_AP_PERF_ARM_CCN_ONLINE); 1579 1591 platform_driver_unregister(&arm_ccn_driver); 1580 1592 } 1581 1593
+12 -58
drivers/bus/mips_cdmm.c
··· 596 596 BUILD_PERDEV_HELPER(cpu_up) /* int mips_cdmm_cpu_up_helper(...) */ 597 597 598 598 /** 599 - * mips_cdmm_bus_down() - Tear down the CDMM bus. 600 - * @data: Pointer to unsigned int CPU number. 599 + * mips_cdmm_cpu_down_prep() - Callback for CPUHP DOWN_PREP: 600 + * Tear down the CDMM bus. 601 + * @cpu: unsigned int CPU number. 601 602 * 602 603 * This function is executed on the hotplugged CPU and calls the CDMM 603 604 * driver cpu_down callback for all devices on that CPU. 604 605 */ 605 - static long mips_cdmm_bus_down(void *data) 606 + static int mips_cdmm_cpu_down_prep(unsigned int cpu) 606 607 { 607 608 struct mips_cdmm_bus *bus; 608 609 long ret; 609 610 610 611 /* Inform all the devices on the bus */ 611 - ret = bus_for_each_dev(&mips_cdmm_bustype, NULL, data, 612 + ret = bus_for_each_dev(&mips_cdmm_bustype, NULL, &cpu, 612 613 mips_cdmm_cpu_down_helper); 613 614 614 615 /* ··· 624 623 } 625 624 626 625 /** 627 - * mips_cdmm_bus_up() - Bring up the CDMM bus. 628 - * @data: Pointer to unsigned int CPU number. 626 + * mips_cdmm_cpu_online() - Callback for CPUHP ONLINE: Bring up the CDMM bus. 627 + * @cpu: unsigned int CPU number. 629 628 * 630 629 * This work_on_cpu callback function is executed on a given CPU to discover 631 630 * CDMM devices on that CPU, or to call the CDMM driver cpu_up callback for all ··· 635 634 * initialisation. When CPUs are brought online the function is 636 635 * invoked directly on the hotplugged CPU. 637 636 */ 638 - static long mips_cdmm_bus_up(void *data) 637 + static int mips_cdmm_cpu_online(unsigned int cpu) 639 638 { 640 639 struct mips_cdmm_bus *bus; 641 640 long ret; ··· 652 651 mips_cdmm_bus_discover(bus); 653 652 else 654 653 /* Inform all the devices on the bus */ 655 - ret = bus_for_each_dev(&mips_cdmm_bustype, NULL, data, 654 + ret = bus_for_each_dev(&mips_cdmm_bustype, NULL, &cpu, 656 655 mips_cdmm_cpu_up_helper); 657 656 658 657 return ret; 659 658 } 660 - 661 - /** 662 - * mips_cdmm_cpu_notify() - Take action when a CPU is going online or offline. 663 - * @nb: CPU notifier block . 664 - * @action: Event that has taken place (CPU_*). 665 - * @data: CPU number. 666 - * 667 - * This notifier is used to keep the CDMM buses updated as CPUs are offlined and 668 - * onlined. When CPUs go offline or come back online, so does their CDMM bus, so 669 - * devices must be informed. Also when CPUs come online for the first time the 670 - * devices on the CDMM bus need discovering. 671 - * 672 - * Returns: NOTIFY_OK if event was used. 673 - * NOTIFY_DONE if we didn't care. 674 - */ 675 - static int mips_cdmm_cpu_notify(struct notifier_block *nb, 676 - unsigned long action, void *data) 677 - { 678 - unsigned int cpu = (unsigned int)data; 679 - 680 - switch (action & ~CPU_TASKS_FROZEN) { 681 - case CPU_ONLINE: 682 - case CPU_DOWN_FAILED: 683 - mips_cdmm_bus_up(&cpu); 684 - break; 685 - case CPU_DOWN_PREPARE: 686 - mips_cdmm_bus_down(&cpu); 687 - break; 688 - default: 689 - return NOTIFY_DONE; 690 - } 691 - 692 - return NOTIFY_OK; 693 - } 694 - 695 - static struct notifier_block mips_cdmm_cpu_nb = { 696 - .notifier_call = mips_cdmm_cpu_notify, 697 - }; 698 659 699 660 /** 700 661 * mips_cdmm_init() - Initialise CDMM bus. ··· 666 703 */ 667 704 static int __init mips_cdmm_init(void) 668 705 { 669 - unsigned int cpu; 670 706 int ret; 671 707 672 708 /* Register the bus */ ··· 674 712 return ret; 675 713 676 714 /* We want to be notified about new CPUs */ 677 - ret = register_cpu_notifier(&mips_cdmm_cpu_nb); 678 - if (ret) { 715 + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "bus/cdmm:online", 716 + mips_cdmm_cpu_online, mips_cdmm_cpu_down_prep); 717 + if (ret < 0) 679 718 pr_warn("cdmm: Failed to register CPU notifier\n"); 680 - goto out; 681 - } 682 719 683 - /* Discover devices on CDMM of online CPUs */ 684 - for_each_online_cpu(cpu) 685 - work_on_cpu(cpu, mips_cdmm_bus_up, &cpu); 686 - 687 - return 0; 688 - out: 689 - bus_unregister(&mips_cdmm_bustype); 690 720 return ret; 691 721 } 692 722 subsys_initcall(mips_cdmm_init);
+14 -27
drivers/cpufreq/cpufreq.c
··· 1286 1286 return ret; 1287 1287 } 1288 1288 1289 - static void cpufreq_offline(unsigned int cpu); 1289 + static int cpufreq_offline(unsigned int cpu); 1290 1290 1291 1291 /** 1292 1292 * cpufreq_add_dev - the cpufreq interface for a CPU device. ··· 1321 1321 return ret; 1322 1322 } 1323 1323 1324 - static void cpufreq_offline(unsigned int cpu) 1324 + static int cpufreq_offline(unsigned int cpu) 1325 1325 { 1326 1326 struct cpufreq_policy *policy; 1327 1327 int ret; ··· 1331 1331 policy = cpufreq_cpu_get_raw(cpu); 1332 1332 if (!policy) { 1333 1333 pr_debug("%s: No cpu_data found\n", __func__); 1334 - return; 1334 + return 0; 1335 1335 } 1336 1336 1337 1337 down_write(&policy->rwsem); ··· 1380 1380 1381 1381 unlock: 1382 1382 up_write(&policy->rwsem); 1383 + return 0; 1383 1384 } 1384 1385 1385 1386 /** ··· 2296 2295 } 2297 2296 EXPORT_SYMBOL(cpufreq_update_policy); 2298 2297 2299 - static int cpufreq_cpu_callback(struct notifier_block *nfb, 2300 - unsigned long action, void *hcpu) 2301 - { 2302 - unsigned int cpu = (unsigned long)hcpu; 2303 - 2304 - switch (action & ~CPU_TASKS_FROZEN) { 2305 - case CPU_ONLINE: 2306 - case CPU_DOWN_FAILED: 2307 - cpufreq_online(cpu); 2308 - break; 2309 - 2310 - case CPU_DOWN_PREPARE: 2311 - cpufreq_offline(cpu); 2312 - break; 2313 - } 2314 - return NOTIFY_OK; 2315 - } 2316 - 2317 - static struct notifier_block __refdata cpufreq_cpu_notifier = { 2318 - .notifier_call = cpufreq_cpu_callback, 2319 - }; 2320 - 2321 2298 /********************************************************************* 2322 2299 * BOOST * 2323 2300 *********************************************************************/ ··· 2397 2418 /********************************************************************* 2398 2419 * REGISTER / UNREGISTER CPUFREQ DRIVER * 2399 2420 *********************************************************************/ 2421 + static enum cpuhp_state hp_online; 2400 2422 2401 2423 /** 2402 2424 * cpufreq_register_driver - register a CPU Frequency driver ··· 2460 2480 goto err_if_unreg; 2461 2481 } 2462 2482 2463 - register_hotcpu_notifier(&cpufreq_cpu_notifier); 2483 + ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "cpufreq:online", 2484 + cpufreq_online, 2485 + cpufreq_offline); 2486 + if (ret < 0) 2487 + goto err_if_unreg; 2488 + hp_online = ret; 2489 + ret = 0; 2490 + 2464 2491 pr_debug("driver %s up and running\n", driver_data->name); 2465 2492 goto out; 2466 2493 ··· 2506 2519 get_online_cpus(); 2507 2520 subsys_interface_unregister(&cpufreq_interface); 2508 2521 remove_boost_sysfs_file(); 2509 - unregister_hotcpu_notifier(&cpufreq_cpu_notifier); 2522 + cpuhp_remove_state_nocalls(hp_online); 2510 2523 2511 2524 write_lock_irqsave(&cpufreq_driver_lock, flags); 2512 2525
+31 -44
drivers/cpuidle/coupled.c
··· 749 749 put_cpu(); 750 750 } 751 751 752 - /** 753 - * cpuidle_coupled_cpu_notify - notifier called during hotplug transitions 754 - * @nb: notifier block 755 - * @action: hotplug transition 756 - * @hcpu: target cpu number 757 - * 758 - * Called when a cpu is brought on or offline using hotplug. Updates the 759 - * coupled cpu set appropriately 760 - */ 761 - static int cpuidle_coupled_cpu_notify(struct notifier_block *nb, 762 - unsigned long action, void *hcpu) 752 + static int coupled_cpu_online(unsigned int cpu) 763 753 { 764 - int cpu = (unsigned long)hcpu; 765 754 struct cpuidle_device *dev; 766 - 767 - switch (action & ~CPU_TASKS_FROZEN) { 768 - case CPU_UP_PREPARE: 769 - case CPU_DOWN_PREPARE: 770 - case CPU_ONLINE: 771 - case CPU_DEAD: 772 - case CPU_UP_CANCELED: 773 - case CPU_DOWN_FAILED: 774 - break; 775 - default: 776 - return NOTIFY_OK; 777 - } 778 755 779 756 mutex_lock(&cpuidle_lock); 780 757 781 758 dev = per_cpu(cpuidle_devices, cpu); 782 - if (!dev || !dev->coupled) 783 - goto out; 784 - 785 - switch (action & ~CPU_TASKS_FROZEN) { 786 - case CPU_UP_PREPARE: 787 - case CPU_DOWN_PREPARE: 788 - cpuidle_coupled_prevent_idle(dev->coupled); 789 - break; 790 - case CPU_ONLINE: 791 - case CPU_DEAD: 759 + if (dev && dev->coupled) { 792 760 cpuidle_coupled_update_online_cpus(dev->coupled); 793 - /* Fall through */ 794 - case CPU_UP_CANCELED: 795 - case CPU_DOWN_FAILED: 796 761 cpuidle_coupled_allow_idle(dev->coupled); 797 - break; 798 762 } 799 763 800 - out: 801 764 mutex_unlock(&cpuidle_lock); 802 - return NOTIFY_OK; 765 + return 0; 803 766 } 804 767 805 - static struct notifier_block cpuidle_coupled_cpu_notifier = { 806 - .notifier_call = cpuidle_coupled_cpu_notify, 807 - }; 768 + static int coupled_cpu_up_prepare(unsigned int cpu) 769 + { 770 + struct cpuidle_device *dev; 771 + 772 + mutex_lock(&cpuidle_lock); 773 + 774 + dev = per_cpu(cpuidle_devices, cpu); 775 + if (dev && dev->coupled) 776 + cpuidle_coupled_prevent_idle(dev->coupled); 777 + 778 + mutex_unlock(&cpuidle_lock); 779 + return 0; 780 + } 808 781 809 782 static int __init cpuidle_coupled_init(void) 810 783 { 811 - return register_cpu_notifier(&cpuidle_coupled_cpu_notifier); 784 + int ret; 785 + 786 + ret = cpuhp_setup_state_nocalls(CPUHP_CPUIDLE_COUPLED_PREPARE, 787 + "cpuidle/coupled:prepare", 788 + coupled_cpu_up_prepare, 789 + coupled_cpu_online); 790 + if (ret) 791 + return ret; 792 + ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, 793 + "cpuidle/coupled:online", 794 + coupled_cpu_online, 795 + coupled_cpu_up_prepare); 796 + if (ret < 0) 797 + cpuhp_remove_state_nocalls(CPUHP_CPUIDLE_COUPLED_PREPARE); 798 + return ret; 812 799 } 813 800 core_initcall(cpuidle_coupled_init);
+25 -28
drivers/cpuidle/cpuidle-powernv.c
··· 119 119 .enter = snooze_loop }, 120 120 }; 121 121 122 - static int powernv_cpuidle_add_cpu_notifier(struct notifier_block *n, 123 - unsigned long action, void *hcpu) 122 + static int powernv_cpuidle_cpu_online(unsigned int cpu) 124 123 { 125 - int hotcpu = (unsigned long)hcpu; 126 - struct cpuidle_device *dev = 127 - per_cpu(cpuidle_devices, hotcpu); 124 + struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); 128 125 129 126 if (dev && cpuidle_get_driver()) { 130 - switch (action) { 131 - case CPU_ONLINE: 132 - case CPU_ONLINE_FROZEN: 133 - cpuidle_pause_and_lock(); 134 - cpuidle_enable_device(dev); 135 - cpuidle_resume_and_unlock(); 136 - break; 137 - 138 - case CPU_DEAD: 139 - case CPU_DEAD_FROZEN: 140 - cpuidle_pause_and_lock(); 141 - cpuidle_disable_device(dev); 142 - cpuidle_resume_and_unlock(); 143 - break; 144 - 145 - default: 146 - return NOTIFY_DONE; 147 - } 127 + cpuidle_pause_and_lock(); 128 + cpuidle_enable_device(dev); 129 + cpuidle_resume_and_unlock(); 148 130 } 149 - return NOTIFY_OK; 131 + return 0; 150 132 } 151 133 152 - static struct notifier_block setup_hotplug_notifier = { 153 - .notifier_call = powernv_cpuidle_add_cpu_notifier, 154 - }; 134 + static int powernv_cpuidle_cpu_dead(unsigned int cpu) 135 + { 136 + struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); 137 + 138 + if (dev && cpuidle_get_driver()) { 139 + cpuidle_pause_and_lock(); 140 + cpuidle_disable_device(dev); 141 + cpuidle_resume_and_unlock(); 142 + } 143 + return 0; 144 + } 155 145 156 146 /* 157 147 * powernv_cpuidle_driver_init() ··· 345 355 return retval; 346 356 } 347 357 348 - register_cpu_notifier(&setup_hotplug_notifier); 358 + retval = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, 359 + "cpuidle/powernv:online", 360 + powernv_cpuidle_cpu_online, NULL); 361 + WARN_ON(retval < 0); 362 + retval = cpuhp_setup_state_nocalls(CPUHP_CPUIDLE_DEAD, 363 + "cpuidle/powernv:dead", NULL, 364 + powernv_cpuidle_cpu_dead); 365 + WARN_ON(retval < 0); 349 366 printk(KERN_DEBUG "powernv_idle_driver registered\n"); 350 367 return 0; 351 368 }
+25 -28
drivers/cpuidle/cpuidle-pseries.c
··· 171 171 .enter = &shared_cede_loop }, 172 172 }; 173 173 174 - static int pseries_cpuidle_add_cpu_notifier(struct notifier_block *n, 175 - unsigned long action, void *hcpu) 174 + static int pseries_cpuidle_cpu_online(unsigned int cpu) 176 175 { 177 - int hotcpu = (unsigned long)hcpu; 178 - struct cpuidle_device *dev = 179 - per_cpu(cpuidle_devices, hotcpu); 176 + struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); 180 177 181 178 if (dev && cpuidle_get_driver()) { 182 - switch (action) { 183 - case CPU_ONLINE: 184 - case CPU_ONLINE_FROZEN: 185 - cpuidle_pause_and_lock(); 186 - cpuidle_enable_device(dev); 187 - cpuidle_resume_and_unlock(); 188 - break; 189 - 190 - case CPU_DEAD: 191 - case CPU_DEAD_FROZEN: 192 - cpuidle_pause_and_lock(); 193 - cpuidle_disable_device(dev); 194 - cpuidle_resume_and_unlock(); 195 - break; 196 - 197 - default: 198 - return NOTIFY_DONE; 199 - } 179 + cpuidle_pause_and_lock(); 180 + cpuidle_enable_device(dev); 181 + cpuidle_resume_and_unlock(); 200 182 } 201 - return NOTIFY_OK; 183 + return 0; 202 184 } 203 185 204 - static struct notifier_block setup_hotplug_notifier = { 205 - .notifier_call = pseries_cpuidle_add_cpu_notifier, 206 - }; 186 + static int pseries_cpuidle_cpu_dead(unsigned int cpu) 187 + { 188 + struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); 189 + 190 + if (dev && cpuidle_get_driver()) { 191 + cpuidle_pause_and_lock(); 192 + cpuidle_disable_device(dev); 193 + cpuidle_resume_and_unlock(); 194 + } 195 + return 0; 196 + } 207 197 208 198 /* 209 199 * pseries_cpuidle_driver_init() ··· 263 273 return retval; 264 274 } 265 275 266 - register_cpu_notifier(&setup_hotplug_notifier); 276 + retval = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, 277 + "cpuidle/pseries:online", 278 + pseries_cpuidle_cpu_online, NULL); 279 + WARN_ON(retval < 0); 280 + retval = cpuhp_setup_state_nocalls(CPUHP_CPUIDLE_DEAD, 281 + "cpuidle/pseries:DEAD", NULL, 282 + pseries_cpuidle_cpu_dead); 283 + WARN_ON(retval < 0); 267 284 printk(KERN_DEBUG "pseries_idle_driver registered\n"); 268 285 return 0; 269 286 }
+29 -55
drivers/md/raid5.c
··· 6349 6349 return 0; 6350 6350 } 6351 6351 6352 + static int raid456_cpu_dead(unsigned int cpu, struct hlist_node *node) 6353 + { 6354 + struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); 6355 + 6356 + free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu)); 6357 + return 0; 6358 + } 6359 + 6352 6360 static void raid5_free_percpu(struct r5conf *conf) 6353 6361 { 6354 - unsigned long cpu; 6355 - 6356 6362 if (!conf->percpu) 6357 6363 return; 6358 6364 6359 - #ifdef CONFIG_HOTPLUG_CPU 6360 - unregister_cpu_notifier(&conf->cpu_notify); 6361 - #endif 6362 - 6363 - get_online_cpus(); 6364 - for_each_possible_cpu(cpu) 6365 - free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu)); 6366 - put_online_cpus(); 6367 - 6365 + cpuhp_state_remove_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); 6368 6366 free_percpu(conf->percpu); 6369 6367 } 6370 6368 ··· 6381 6383 kfree(conf); 6382 6384 } 6383 6385 6384 - #ifdef CONFIG_HOTPLUG_CPU 6385 - static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action, 6386 - void *hcpu) 6386 + static int raid456_cpu_up_prepare(unsigned int cpu, struct hlist_node *node) 6387 6387 { 6388 - struct r5conf *conf = container_of(nfb, struct r5conf, cpu_notify); 6389 - long cpu = (long)hcpu; 6388 + struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); 6390 6389 struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); 6391 6390 6392 - switch (action) { 6393 - case CPU_UP_PREPARE: 6394 - case CPU_UP_PREPARE_FROZEN: 6395 - if (alloc_scratch_buffer(conf, percpu)) { 6396 - pr_err("%s: failed memory allocation for cpu%ld\n", 6397 - __func__, cpu); 6398 - return notifier_from_errno(-ENOMEM); 6399 - } 6400 - break; 6401 - case CPU_DEAD: 6402 - case CPU_DEAD_FROZEN: 6403 - case CPU_UP_CANCELED: 6404 - case CPU_UP_CANCELED_FROZEN: 6405 - free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu)); 6406 - break; 6407 - default: 6408 - break; 6391 + if (alloc_scratch_buffer(conf, percpu)) { 6392 + pr_err("%s: failed memory allocation for cpu%u\n", 6393 + __func__, cpu); 6394 + return -ENOMEM; 6409 6395 } 6410 - return NOTIFY_OK; 6396 + return 0; 6411 6397 } 6412 - #endif 6413 6398 6414 6399 static int raid5_alloc_percpu(struct r5conf *conf) 6415 6400 { 6416 - unsigned long cpu; 6417 6401 int err = 0; 6418 6402 6419 6403 conf->percpu = alloc_percpu(struct raid5_percpu); 6420 6404 if (!conf->percpu) 6421 6405 return -ENOMEM; 6422 6406 6423 - #ifdef CONFIG_HOTPLUG_CPU 6424 - conf->cpu_notify.notifier_call = raid456_cpu_notify; 6425 - conf->cpu_notify.priority = 0; 6426 - err = register_cpu_notifier(&conf->cpu_notify); 6427 - if (err) 6428 - return err; 6429 - #endif 6430 - 6431 - get_online_cpus(); 6432 - for_each_present_cpu(cpu) { 6433 - err = alloc_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu)); 6434 - if (err) { 6435 - pr_err("%s: failed memory allocation for cpu%ld\n", 6436 - __func__, cpu); 6437 - break; 6438 - } 6439 - } 6440 - put_online_cpus(); 6441 - 6407 + err = cpuhp_state_add_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); 6442 6408 if (!err) { 6443 6409 conf->scribble_disks = max(conf->raid_disks, 6444 6410 conf->previous_raid_disks); ··· 7947 7985 7948 7986 static int __init raid5_init(void) 7949 7987 { 7988 + int ret; 7989 + 7950 7990 raid5_wq = alloc_workqueue("raid5wq", 7951 7991 WQ_UNBOUND|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE|WQ_SYSFS, 0); 7952 7992 if (!raid5_wq) 7953 7993 return -ENOMEM; 7994 + 7995 + ret = cpuhp_setup_state_multi(CPUHP_MD_RAID5_PREPARE, 7996 + "md/raid5:prepare", 7997 + raid456_cpu_up_prepare, 7998 + raid456_cpu_dead); 7999 + if (ret) { 8000 + destroy_workqueue(raid5_wq); 8001 + return ret; 8002 + } 7954 8003 register_md_personality(&raid6_personality); 7955 8004 register_md_personality(&raid5_personality); 7956 8005 register_md_personality(&raid4_personality); ··· 7973 8000 unregister_md_personality(&raid6_personality); 7974 8001 unregister_md_personality(&raid5_personality); 7975 8002 unregister_md_personality(&raid4_personality); 8003 + cpuhp_remove_multi_state(CPUHP_MD_RAID5_PREPARE); 7976 8004 destroy_workqueue(raid5_wq); 7977 8005 } 7978 8006
+1 -3
drivers/md/raid5.h
··· 512 512 } __percpu *percpu; 513 513 int scribble_disks; 514 514 int scribble_sectors; 515 - #ifdef CONFIG_HOTPLUG_CPU 516 - struct notifier_block cpu_notify; 517 - #endif 515 + struct hlist_node node; 518 516 519 517 /* 520 518 * Free stripes pool
+150 -96
drivers/net/ethernet/marvell/mvneta.c
··· 382 382 struct mvneta_rx_queue *rxqs; 383 383 struct mvneta_tx_queue *txqs; 384 384 struct net_device *dev; 385 - struct notifier_block cpu_notifier; 385 + struct hlist_node node_online; 386 + struct hlist_node node_dead; 386 387 int rxq_def; 387 388 /* Protect the access to the percpu interrupt registers, 388 389 * ensuring that the configuration remains coherent. ··· 575 574 int next_desc_to_proc; 576 575 }; 577 576 577 + static enum cpuhp_state online_hpstate; 578 578 /* The hardware supports eight (8) rx queues, but we are only allowing 579 579 * the first one to be used. Therefore, let's just allocate one queue. 580 580 */ ··· 3313 3311 } 3314 3312 }; 3315 3313 3316 - static int mvneta_percpu_notifier(struct notifier_block *nfb, 3317 - unsigned long action, void *hcpu) 3314 + static int mvneta_cpu_online(unsigned int cpu, struct hlist_node *node) 3318 3315 { 3319 - struct mvneta_port *pp = container_of(nfb, struct mvneta_port, 3320 - cpu_notifier); 3321 - int cpu = (unsigned long)hcpu, other_cpu; 3316 + int other_cpu; 3317 + struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port, 3318 + node_online); 3322 3319 struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu); 3323 3320 3324 - switch (action) { 3325 - case CPU_ONLINE: 3326 - case CPU_ONLINE_FROZEN: 3327 - case CPU_DOWN_FAILED: 3328 - case CPU_DOWN_FAILED_FROZEN: 3329 - spin_lock(&pp->lock); 3330 - /* Configuring the driver for a new CPU while the 3331 - * driver is stopping is racy, so just avoid it. 3332 - */ 3333 - if (pp->is_stopped) { 3334 - spin_unlock(&pp->lock); 3335 - break; 3321 + 3322 + spin_lock(&pp->lock); 3323 + /* 3324 + * Configuring the driver for a new CPU while the driver is 3325 + * stopping is racy, so just avoid it. 3326 + */ 3327 + if (pp->is_stopped) { 3328 + spin_unlock(&pp->lock); 3329 + return 0; 3330 + } 3331 + netif_tx_stop_all_queues(pp->dev); 3332 + 3333 + /* 3334 + * We have to synchronise on tha napi of each CPU except the one 3335 + * just being woken up 3336 + */ 3337 + for_each_online_cpu(other_cpu) { 3338 + if (other_cpu != cpu) { 3339 + struct mvneta_pcpu_port *other_port = 3340 + per_cpu_ptr(pp->ports, other_cpu); 3341 + 3342 + napi_synchronize(&other_port->napi); 3336 3343 } 3337 - netif_tx_stop_all_queues(pp->dev); 3338 - 3339 - /* We have to synchronise on tha napi of each CPU 3340 - * except the one just being waked up 3341 - */ 3342 - for_each_online_cpu(other_cpu) { 3343 - if (other_cpu != cpu) { 3344 - struct mvneta_pcpu_port *other_port = 3345 - per_cpu_ptr(pp->ports, other_cpu); 3346 - 3347 - napi_synchronize(&other_port->napi); 3348 - } 3349 - } 3350 - 3351 - /* Mask all ethernet port interrupts */ 3352 - on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); 3353 - napi_enable(&port->napi); 3354 - 3355 - 3356 - /* Enable per-CPU interrupts on the CPU that is 3357 - * brought up. 3358 - */ 3359 - mvneta_percpu_enable(pp); 3360 - 3361 - /* Enable per-CPU interrupt on the one CPU we care 3362 - * about. 3363 - */ 3364 - mvneta_percpu_elect(pp); 3365 - 3366 - /* Unmask all ethernet port interrupts */ 3367 - on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true); 3368 - mvreg_write(pp, MVNETA_INTR_MISC_MASK, 3369 - MVNETA_CAUSE_PHY_STATUS_CHANGE | 3370 - MVNETA_CAUSE_LINK_CHANGE | 3371 - MVNETA_CAUSE_PSC_SYNC_CHANGE); 3372 - netif_tx_start_all_queues(pp->dev); 3373 - spin_unlock(&pp->lock); 3374 - break; 3375 - case CPU_DOWN_PREPARE: 3376 - case CPU_DOWN_PREPARE_FROZEN: 3377 - netif_tx_stop_all_queues(pp->dev); 3378 - /* Thanks to this lock we are sure that any pending 3379 - * cpu election is done 3380 - */ 3381 - spin_lock(&pp->lock); 3382 - /* Mask all ethernet port interrupts */ 3383 - on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); 3384 - spin_unlock(&pp->lock); 3385 - 3386 - napi_synchronize(&port->napi); 3387 - napi_disable(&port->napi); 3388 - /* Disable per-CPU interrupts on the CPU that is 3389 - * brought down. 3390 - */ 3391 - mvneta_percpu_disable(pp); 3392 - 3393 - break; 3394 - case CPU_DEAD: 3395 - case CPU_DEAD_FROZEN: 3396 - /* Check if a new CPU must be elected now this on is down */ 3397 - spin_lock(&pp->lock); 3398 - mvneta_percpu_elect(pp); 3399 - spin_unlock(&pp->lock); 3400 - /* Unmask all ethernet port interrupts */ 3401 - on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true); 3402 - mvreg_write(pp, MVNETA_INTR_MISC_MASK, 3403 - MVNETA_CAUSE_PHY_STATUS_CHANGE | 3404 - MVNETA_CAUSE_LINK_CHANGE | 3405 - MVNETA_CAUSE_PSC_SYNC_CHANGE); 3406 - netif_tx_start_all_queues(pp->dev); 3407 - break; 3408 3344 } 3409 3345 3410 - return NOTIFY_OK; 3346 + /* Mask all ethernet port interrupts */ 3347 + on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); 3348 + napi_enable(&port->napi); 3349 + 3350 + /* 3351 + * Enable per-CPU interrupts on the CPU that is 3352 + * brought up. 3353 + */ 3354 + mvneta_percpu_enable(pp); 3355 + 3356 + /* 3357 + * Enable per-CPU interrupt on the one CPU we care 3358 + * about. 3359 + */ 3360 + mvneta_percpu_elect(pp); 3361 + 3362 + /* Unmask all ethernet port interrupts */ 3363 + on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true); 3364 + mvreg_write(pp, MVNETA_INTR_MISC_MASK, 3365 + MVNETA_CAUSE_PHY_STATUS_CHANGE | 3366 + MVNETA_CAUSE_LINK_CHANGE | 3367 + MVNETA_CAUSE_PSC_SYNC_CHANGE); 3368 + netif_tx_start_all_queues(pp->dev); 3369 + spin_unlock(&pp->lock); 3370 + return 0; 3371 + } 3372 + 3373 + static int mvneta_cpu_down_prepare(unsigned int cpu, struct hlist_node *node) 3374 + { 3375 + struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port, 3376 + node_online); 3377 + struct mvneta_pcpu_port *port = per_cpu_ptr(pp->ports, cpu); 3378 + 3379 + /* 3380 + * Thanks to this lock we are sure that any pending cpu election is 3381 + * done. 3382 + */ 3383 + spin_lock(&pp->lock); 3384 + /* Mask all ethernet port interrupts */ 3385 + on_each_cpu(mvneta_percpu_mask_interrupt, pp, true); 3386 + spin_unlock(&pp->lock); 3387 + 3388 + napi_synchronize(&port->napi); 3389 + napi_disable(&port->napi); 3390 + /* Disable per-CPU interrupts on the CPU that is brought down. */ 3391 + mvneta_percpu_disable(pp); 3392 + return 0; 3393 + } 3394 + 3395 + static int mvneta_cpu_dead(unsigned int cpu, struct hlist_node *node) 3396 + { 3397 + struct mvneta_port *pp = hlist_entry_safe(node, struct mvneta_port, 3398 + node_dead); 3399 + 3400 + /* Check if a new CPU must be elected now this on is down */ 3401 + spin_lock(&pp->lock); 3402 + mvneta_percpu_elect(pp); 3403 + spin_unlock(&pp->lock); 3404 + /* Unmask all ethernet port interrupts */ 3405 + on_each_cpu(mvneta_percpu_unmask_interrupt, pp, true); 3406 + mvreg_write(pp, MVNETA_INTR_MISC_MASK, 3407 + MVNETA_CAUSE_PHY_STATUS_CHANGE | 3408 + MVNETA_CAUSE_LINK_CHANGE | 3409 + MVNETA_CAUSE_PSC_SYNC_CHANGE); 3410 + netif_tx_start_all_queues(pp->dev); 3411 + return 0; 3411 3412 } 3412 3413 3413 3414 static int mvneta_open(struct net_device *dev) ··· 3447 3442 /* Register a CPU notifier to handle the case where our CPU 3448 3443 * might be taken offline. 3449 3444 */ 3450 - register_cpu_notifier(&pp->cpu_notifier); 3445 + ret = cpuhp_state_add_instance_nocalls(online_hpstate, 3446 + &pp->node_online); 3447 + if (ret) 3448 + goto err_free_irq; 3449 + 3450 + ret = cpuhp_state_add_instance_nocalls(CPUHP_NET_MVNETA_DEAD, 3451 + &pp->node_dead); 3452 + if (ret) 3453 + goto err_free_online_hp; 3451 3454 3452 3455 /* In default link is down */ 3453 3456 netif_carrier_off(pp->dev); ··· 3463 3450 ret = mvneta_mdio_probe(pp); 3464 3451 if (ret < 0) { 3465 3452 netdev_err(dev, "cannot probe MDIO bus\n"); 3466 - goto err_free_irq; 3453 + goto err_free_dead_hp; 3467 3454 } 3468 3455 3469 3456 mvneta_start_dev(pp); 3470 3457 3471 3458 return 0; 3472 3459 3460 + err_free_dead_hp: 3461 + cpuhp_state_remove_instance_nocalls(CPUHP_NET_MVNETA_DEAD, 3462 + &pp->node_dead); 3463 + err_free_online_hp: 3464 + cpuhp_state_remove_instance_nocalls(online_hpstate, &pp->node_online); 3473 3465 err_free_irq: 3474 - unregister_cpu_notifier(&pp->cpu_notifier); 3475 3466 on_each_cpu(mvneta_percpu_disable, pp, true); 3476 3467 free_percpu_irq(pp->dev->irq, pp->ports); 3477 3468 err_cleanup_txqs: ··· 3501 3484 3502 3485 mvneta_stop_dev(pp); 3503 3486 mvneta_mdio_remove(pp); 3504 - unregister_cpu_notifier(&pp->cpu_notifier); 3487 + 3488 + cpuhp_state_remove_instance_nocalls(online_hpstate, &pp->node_online); 3489 + cpuhp_state_remove_instance_nocalls(CPUHP_NET_MVNETA_DEAD, 3490 + &pp->node_dead); 3505 3491 on_each_cpu(mvneta_percpu_disable, pp, true); 3506 3492 free_percpu_irq(dev->irq, pp->ports); 3507 3493 mvneta_cleanup_rxqs(pp); ··· 4044 4024 err = of_property_read_string(dn, "managed", &managed); 4045 4025 pp->use_inband_status = (err == 0 && 4046 4026 strcmp(managed, "in-band-status") == 0); 4047 - pp->cpu_notifier.notifier_call = mvneta_percpu_notifier; 4048 4027 4049 4028 pp->rxq_def = rxq_def; 4050 4029 ··· 4246 4227 }, 4247 4228 }; 4248 4229 4249 - module_platform_driver(mvneta_driver); 4230 + static int __init mvneta_driver_init(void) 4231 + { 4232 + int ret; 4233 + 4234 + ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "net/mvmeta:online", 4235 + mvneta_cpu_online, 4236 + mvneta_cpu_down_prepare); 4237 + if (ret < 0) 4238 + goto out; 4239 + online_hpstate = ret; 4240 + ret = cpuhp_setup_state_multi(CPUHP_NET_MVNETA_DEAD, "net/mvneta:dead", 4241 + NULL, mvneta_cpu_dead); 4242 + if (ret) 4243 + goto err_dead; 4244 + 4245 + ret = platform_driver_register(&mvneta_driver); 4246 + if (ret) 4247 + goto err; 4248 + return 0; 4249 + 4250 + err: 4251 + cpuhp_remove_multi_state(CPUHP_NET_MVNETA_DEAD); 4252 + err_dead: 4253 + cpuhp_remove_multi_state(online_hpstate); 4254 + out: 4255 + return ret; 4256 + } 4257 + module_init(mvneta_driver_init); 4258 + 4259 + static void __exit mvneta_driver_exit(void) 4260 + { 4261 + platform_driver_unregister(&mvneta_driver); 4262 + cpuhp_remove_multi_state(CPUHP_NET_MVNETA_DEAD); 4263 + cpuhp_remove_multi_state(online_hpstate); 4264 + } 4265 + module_exit(mvneta_driver_exit); 4250 4266 4251 4267 MODULE_DESCRIPTION("Marvell NETA Ethernet Driver - www.marvell.com"); 4252 4268 MODULE_AUTHOR("Rami Rosen <rosenr@marvell.com>, Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
+86 -24
drivers/net/virtio_net.c
··· 138 138 /* Does the affinity hint is set for virtqueues? */ 139 139 bool affinity_hint_set; 140 140 141 - /* CPU hot plug notifier */ 142 - struct notifier_block nb; 141 + /* CPU hotplug instances for online & dead */ 142 + struct hlist_node node; 143 + struct hlist_node node_dead; 143 144 144 145 /* Control VQ buffers: protected by the rtnl lock */ 145 146 struct virtio_net_ctrl_hdr ctrl_hdr; ··· 1238 1237 vi->affinity_hint_set = true; 1239 1238 } 1240 1239 1241 - static int virtnet_cpu_callback(struct notifier_block *nfb, 1242 - unsigned long action, void *hcpu) 1240 + static int virtnet_cpu_online(unsigned int cpu, struct hlist_node *node) 1243 1241 { 1244 - struct virtnet_info *vi = container_of(nfb, struct virtnet_info, nb); 1242 + struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, 1243 + node); 1244 + virtnet_set_affinity(vi); 1245 + return 0; 1246 + } 1245 1247 1246 - switch(action & ~CPU_TASKS_FROZEN) { 1247 - case CPU_ONLINE: 1248 - case CPU_DOWN_FAILED: 1249 - case CPU_DEAD: 1250 - virtnet_set_affinity(vi); 1251 - break; 1252 - case CPU_DOWN_PREPARE: 1253 - virtnet_clean_affinity(vi, (long)hcpu); 1254 - break; 1255 - default: 1256 - break; 1257 - } 1248 + static int virtnet_cpu_dead(unsigned int cpu, struct hlist_node *node) 1249 + { 1250 + struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, 1251 + node_dead); 1252 + virtnet_set_affinity(vi); 1253 + return 0; 1254 + } 1258 1255 1259 - return NOTIFY_OK; 1256 + static int virtnet_cpu_down_prep(unsigned int cpu, struct hlist_node *node) 1257 + { 1258 + struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, 1259 + node); 1260 + 1261 + virtnet_clean_affinity(vi, cpu); 1262 + return 0; 1263 + } 1264 + 1265 + static enum cpuhp_state virtionet_online; 1266 + 1267 + static int virtnet_cpu_notif_add(struct virtnet_info *vi) 1268 + { 1269 + int ret; 1270 + 1271 + ret = cpuhp_state_add_instance_nocalls(virtionet_online, &vi->node); 1272 + if (ret) 1273 + return ret; 1274 + ret = cpuhp_state_add_instance_nocalls(CPUHP_VIRT_NET_DEAD, 1275 + &vi->node_dead); 1276 + if (!ret) 1277 + return ret; 1278 + cpuhp_state_remove_instance_nocalls(virtionet_online, &vi->node); 1279 + return ret; 1280 + } 1281 + 1282 + static void virtnet_cpu_notif_remove(struct virtnet_info *vi) 1283 + { 1284 + cpuhp_state_remove_instance_nocalls(virtionet_online, &vi->node); 1285 + cpuhp_state_remove_instance_nocalls(CPUHP_VIRT_NET_DEAD, 1286 + &vi->node_dead); 1260 1287 } 1261 1288 1262 1289 static void virtnet_get_ringparam(struct net_device *dev, ··· 1908 1879 1909 1880 virtio_device_ready(vdev); 1910 1881 1911 - vi->nb.notifier_call = &virtnet_cpu_callback; 1912 - err = register_hotcpu_notifier(&vi->nb); 1882 + err = virtnet_cpu_notif_add(vi); 1913 1883 if (err) { 1914 1884 pr_debug("virtio_net: registering cpu notifier failed\n"); 1915 1885 goto free_unregister_netdev; ··· 1962 1934 { 1963 1935 struct virtnet_info *vi = vdev->priv; 1964 1936 1965 - unregister_hotcpu_notifier(&vi->nb); 1937 + virtnet_cpu_notif_remove(vi); 1966 1938 1967 1939 /* Make sure no work handler is accessing the device. */ 1968 1940 flush_work(&vi->config_work); ··· 1981 1953 struct virtnet_info *vi = vdev->priv; 1982 1954 int i; 1983 1955 1984 - unregister_hotcpu_notifier(&vi->nb); 1956 + virtnet_cpu_notif_remove(vi); 1985 1957 1986 1958 /* Make sure no work handler is accessing the device */ 1987 1959 flush_work(&vi->config_work); ··· 2025 1997 virtnet_set_queues(vi, vi->curr_queue_pairs); 2026 1998 rtnl_unlock(); 2027 1999 2028 - err = register_hotcpu_notifier(&vi->nb); 2000 + err = virtnet_cpu_notif_add(vi); 2029 2001 if (err) 2030 2002 return err; 2031 2003 ··· 2067 2039 #endif 2068 2040 }; 2069 2041 2070 - module_virtio_driver(virtio_net_driver); 2042 + static __init int virtio_net_driver_init(void) 2043 + { 2044 + int ret; 2045 + 2046 + ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "AP_VIRT_NET_ONLINE", 2047 + virtnet_cpu_online, 2048 + virtnet_cpu_down_prep); 2049 + if (ret < 0) 2050 + goto out; 2051 + virtionet_online = ret; 2052 + ret = cpuhp_setup_state_multi(CPUHP_VIRT_NET_DEAD, "VIRT_NET_DEAD", 2053 + NULL, virtnet_cpu_dead); 2054 + if (ret) 2055 + goto err_dead; 2056 + 2057 + ret = register_virtio_driver(&virtio_net_driver); 2058 + if (ret) 2059 + goto err_virtio; 2060 + return 0; 2061 + err_virtio: 2062 + cpuhp_remove_multi_state(CPUHP_VIRT_NET_DEAD); 2063 + err_dead: 2064 + cpuhp_remove_multi_state(virtionet_online); 2065 + out: 2066 + return ret; 2067 + } 2068 + module_init(virtio_net_driver_init); 2069 + 2070 + static __exit void virtio_net_driver_exit(void) 2071 + { 2072 + cpuhp_remove_multi_state(CPUHP_VIRT_NET_DEAD); 2073 + cpuhp_remove_multi_state(virtionet_online); 2074 + unregister_virtio_driver(&virtio_net_driver); 2075 + } 2076 + module_exit(virtio_net_driver_exit); 2071 2077 2072 2078 MODULE_DEVICE_TABLE(virtio, id_table); 2073 2079 MODULE_DESCRIPTION("Virtio network driver");
+23 -21
drivers/oprofile/timer_int.c
··· 74 74 put_online_cpus(); 75 75 } 76 76 77 - static int oprofile_cpu_notify(struct notifier_block *self, 78 - unsigned long action, void *hcpu) 77 + static int oprofile_timer_online(unsigned int cpu) 79 78 { 80 - long cpu = (long) hcpu; 81 - 82 - switch (action) { 83 - case CPU_ONLINE: 84 - case CPU_ONLINE_FROZEN: 85 - smp_call_function_single(cpu, __oprofile_hrtimer_start, 86 - NULL, 1); 87 - break; 88 - case CPU_DEAD: 89 - case CPU_DEAD_FROZEN: 90 - __oprofile_hrtimer_stop(cpu); 91 - break; 92 - } 93 - return NOTIFY_OK; 79 + local_irq_disable(); 80 + __oprofile_hrtimer_start(NULL); 81 + local_irq_enable(); 82 + return 0; 94 83 } 95 84 96 - static struct notifier_block __refdata oprofile_cpu_notifier = { 97 - .notifier_call = oprofile_cpu_notify, 98 - }; 85 + static int oprofile_timer_prep_down(unsigned int cpu) 86 + { 87 + __oprofile_hrtimer_stop(cpu); 88 + return 0; 89 + } 90 + 91 + static enum cpuhp_state hp_online; 99 92 100 93 static int oprofile_hrtimer_setup(void) 101 94 { 102 - return register_hotcpu_notifier(&oprofile_cpu_notifier); 95 + int ret; 96 + 97 + ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, 98 + "oprofile/timer:online", 99 + oprofile_timer_online, 100 + oprofile_timer_prep_down); 101 + if (ret < 0) 102 + return ret; 103 + hp_online = ret; 104 + return 0; 103 105 } 104 106 105 107 static void oprofile_hrtimer_shutdown(void) 106 108 { 107 - unregister_hotcpu_notifier(&oprofile_cpu_notifier); 109 + cpuhp_remove_state_nocalls(hp_online); 108 110 } 109 111 110 112 int oprofile_timer_init(struct oprofile_operations *ops)
+18 -26
drivers/perf/arm_pmu.c
··· 709 709 return 0; 710 710 } 711 711 712 - static DEFINE_SPINLOCK(arm_pmu_lock); 713 - static LIST_HEAD(arm_pmu_list); 714 - 715 712 /* 716 713 * PMU hardware loses all context when a CPU goes offline. 717 714 * When a CPU is hotplugged back in, since some hardware registers are 718 715 * UNKNOWN at reset, the PMU must be explicitly reset to avoid reading 719 716 * junk values out of them. 720 717 */ 721 - static int arm_perf_starting_cpu(unsigned int cpu) 718 + static int arm_perf_starting_cpu(unsigned int cpu, struct hlist_node *node) 722 719 { 723 - struct arm_pmu *pmu; 720 + struct arm_pmu *pmu = hlist_entry_safe(node, struct arm_pmu, node); 724 721 725 - spin_lock(&arm_pmu_lock); 726 - list_for_each_entry(pmu, &arm_pmu_list, entry) { 727 - 728 - if (!cpumask_test_cpu(cpu, &pmu->supported_cpus)) 729 - continue; 730 - if (pmu->reset) 731 - pmu->reset(pmu); 732 - } 733 - spin_unlock(&arm_pmu_lock); 722 + if (!cpumask_test_cpu(cpu, &pmu->supported_cpus)) 723 + return 0; 724 + if (pmu->reset) 725 + pmu->reset(pmu); 734 726 return 0; 735 727 } 736 728 ··· 834 842 if (!cpu_hw_events) 835 843 return -ENOMEM; 836 844 837 - spin_lock(&arm_pmu_lock); 838 - list_add_tail(&cpu_pmu->entry, &arm_pmu_list); 839 - spin_unlock(&arm_pmu_lock); 845 + err = cpuhp_state_add_instance_nocalls(CPUHP_AP_PERF_ARM_STARTING, 846 + &cpu_pmu->node); 847 + if (err) 848 + goto out_free; 840 849 841 850 err = cpu_pm_pmu_register(cpu_pmu); 842 851 if (err) ··· 873 880 return 0; 874 881 875 882 out_unregister: 876 - spin_lock(&arm_pmu_lock); 877 - list_del(&cpu_pmu->entry); 878 - spin_unlock(&arm_pmu_lock); 883 + cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_STARTING, 884 + &cpu_pmu->node); 885 + out_free: 879 886 free_percpu(cpu_hw_events); 880 887 return err; 881 888 } ··· 883 890 static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu) 884 891 { 885 892 cpu_pm_pmu_unregister(cpu_pmu); 886 - spin_lock(&arm_pmu_lock); 887 - list_del(&cpu_pmu->entry); 888 - spin_unlock(&arm_pmu_lock); 893 + cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_STARTING, 894 + &cpu_pmu->node); 889 895 free_percpu(cpu_pmu->hw_events); 890 896 } 891 897 ··· 1083 1091 { 1084 1092 int ret; 1085 1093 1086 - ret = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_STARTING, 1087 - "AP_PERF_ARM_STARTING", 1088 - arm_perf_starting_cpu, NULL); 1094 + ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_ARM_STARTING, 1095 + "AP_PERF_ARM_STARTING", 1096 + arm_perf_starting_cpu, NULL); 1089 1097 if (ret) 1090 1098 pr_err("CPU hotplug notifier for ARM PMU could not be registered: %d\n", 1091 1099 ret);
+49 -27
drivers/scsi/virtio_scsi.c
··· 107 107 /* If the affinity hint is set for virtqueues */ 108 108 bool affinity_hint_set; 109 109 110 - /* CPU hotplug notifier */ 111 - struct notifier_block nb; 110 + struct hlist_node node; 111 + struct hlist_node node_dead; 112 112 113 113 /* Protected by event_vq lock */ 114 114 bool stop_events; ··· 118 118 struct virtio_scsi_vq req_vqs[]; 119 119 }; 120 120 121 + static enum cpuhp_state virtioscsi_online; 121 122 static struct kmem_cache *virtscsi_cmd_cache; 122 123 static mempool_t *virtscsi_cmd_pool; 123 124 ··· 853 852 put_online_cpus(); 854 853 } 855 854 856 - static int virtscsi_cpu_callback(struct notifier_block *nfb, 857 - unsigned long action, void *hcpu) 855 + static int virtscsi_cpu_online(unsigned int cpu, struct hlist_node *node) 858 856 { 859 - struct virtio_scsi *vscsi = container_of(nfb, struct virtio_scsi, nb); 860 - switch(action) { 861 - case CPU_ONLINE: 862 - case CPU_ONLINE_FROZEN: 863 - case CPU_DEAD: 864 - case CPU_DEAD_FROZEN: 865 - __virtscsi_set_affinity(vscsi, true); 866 - break; 867 - default: 868 - break; 869 - } 870 - return NOTIFY_OK; 857 + struct virtio_scsi *vscsi = hlist_entry_safe(node, struct virtio_scsi, 858 + node); 859 + __virtscsi_set_affinity(vscsi, true); 860 + return 0; 861 + } 862 + 863 + static int virtscsi_cpu_notif_add(struct virtio_scsi *vi) 864 + { 865 + int ret; 866 + 867 + ret = cpuhp_state_add_instance(virtioscsi_online, &vi->node); 868 + if (ret) 869 + return ret; 870 + 871 + ret = cpuhp_state_add_instance(CPUHP_VIRT_SCSI_DEAD, &vi->node_dead); 872 + if (ret) 873 + cpuhp_state_remove_instance(virtioscsi_online, &vi->node); 874 + return ret; 875 + } 876 + 877 + static void virtscsi_cpu_notif_remove(struct virtio_scsi *vi) 878 + { 879 + cpuhp_state_remove_instance_nocalls(virtioscsi_online, &vi->node); 880 + cpuhp_state_remove_instance_nocalls(CPUHP_VIRT_SCSI_DEAD, 881 + &vi->node_dead); 871 882 } 872 883 873 884 static void virtscsi_init_vq(struct virtio_scsi_vq *virtscsi_vq, ··· 942 929 virtscsi_init_vq(&vscsi->req_vqs[i - VIRTIO_SCSI_VQ_BASE], 943 930 vqs[i]); 944 931 945 - virtscsi_set_affinity(vscsi, true); 946 - 947 932 virtscsi_config_set(vdev, cdb_size, VIRTIO_SCSI_CDB_SIZE); 948 933 virtscsi_config_set(vdev, sense_size, VIRTIO_SCSI_SENSE_SIZE); 949 934 ··· 998 987 if (err) 999 988 goto virtscsi_init_failed; 1000 989 1001 - vscsi->nb.notifier_call = &virtscsi_cpu_callback; 1002 - err = register_hotcpu_notifier(&vscsi->nb); 1003 - if (err) { 1004 - pr_err("registering cpu notifier failed\n"); 990 + err = virtscsi_cpu_notif_add(vscsi); 991 + if (err) 1005 992 goto scsi_add_host_failed; 1006 - } 1007 993 1008 994 cmd_per_lun = virtscsi_config_get(vdev, cmd_per_lun) ?: 1; 1009 995 shost->cmd_per_lun = min_t(u32, cmd_per_lun, shost->can_queue); ··· 1057 1049 1058 1050 scsi_remove_host(shost); 1059 1051 1060 - unregister_hotcpu_notifier(&vscsi->nb); 1052 + virtscsi_cpu_notif_remove(vscsi); 1061 1053 1062 1054 virtscsi_remove_vqs(vdev); 1063 1055 scsi_host_put(shost); ··· 1069 1061 struct Scsi_Host *sh = virtio_scsi_host(vdev); 1070 1062 struct virtio_scsi *vscsi = shost_priv(sh); 1071 1063 1072 - unregister_hotcpu_notifier(&vscsi->nb); 1064 + virtscsi_cpu_notif_remove(vscsi); 1073 1065 virtscsi_remove_vqs(vdev); 1074 1066 return 0; 1075 1067 } ··· 1084 1076 if (err) 1085 1077 return err; 1086 1078 1087 - err = register_hotcpu_notifier(&vscsi->nb); 1079 + err = virtscsi_cpu_notif_add(vscsi); 1088 1080 if (err) { 1089 1081 vdev->config->del_vqs(vdev); 1090 1082 return err; 1091 1083 } 1092 - 1093 1084 virtio_device_ready(vdev); 1094 1085 1095 1086 if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) ··· 1143 1136 pr_err("mempool_create() for virtscsi_cmd_pool failed\n"); 1144 1137 goto error; 1145 1138 } 1139 + ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, 1140 + "scsi/virtio:online", 1141 + virtscsi_cpu_online, NULL); 1142 + if (ret < 0) 1143 + goto error; 1144 + virtioscsi_online = ret; 1145 + ret = cpuhp_setup_state_multi(CPUHP_VIRT_SCSI_DEAD, "scsi/virtio:dead", 1146 + NULL, virtscsi_cpu_online); 1147 + if (ret) 1148 + goto error; 1146 1149 ret = register_virtio_driver(&virtio_scsi_driver); 1147 1150 if (ret < 0) 1148 1151 goto error; ··· 1168 1151 kmem_cache_destroy(virtscsi_cmd_cache); 1169 1152 virtscsi_cmd_cache = NULL; 1170 1153 } 1154 + if (virtioscsi_online) 1155 + cpuhp_remove_multi_state(virtioscsi_online); 1156 + cpuhp_remove_multi_state(CPUHP_VIRT_SCSI_DEAD); 1171 1157 return ret; 1172 1158 } 1173 1159 1174 1160 static void __exit fini(void) 1175 1161 { 1176 1162 unregister_virtio_driver(&virtio_scsi_driver); 1163 + cpuhp_remove_multi_state(virtioscsi_online); 1164 + cpuhp_remove_multi_state(CPUHP_VIRT_SCSI_DEAD); 1177 1165 mempool_destroy(virtscsi_cmd_pool); 1178 1166 kmem_cache_destroy(virtscsi_cmd_cache); 1179 1167 }
+2 -2
include/acpi/processor.h
··· 359 359 * onlined/offlined. In such case the flags.throttling will be updated. 360 360 */ 361 361 extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, 362 - unsigned long action); 362 + bool is_dead); 363 363 extern const struct file_operations acpi_processor_throttling_fops; 364 364 extern void acpi_processor_throttling_init(void); 365 365 #else ··· 380 380 } 381 381 382 382 static inline void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, 383 - unsigned long action) {} 383 + bool is_dead) {} 384 384 385 385 static inline void acpi_processor_throttling_init(void) {} 386 386 #endif /* CONFIG_ACPI_CPU_FREQ_PSS */
-12
include/linux/cpu.h
··· 61 61 #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */ 62 62 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */ 63 63 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */ 64 - #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task, 65 - * not handling interrupts, soon dead. 66 - * Called on the dying cpu, interrupts 67 - * are already disabled. Must not 68 - * sleep, must not fail */ 69 64 #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug 70 65 * lock is dropped */ 71 - #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running. 72 - * Called on the new cpu, just before 73 - * enabling interrupts. Must not sleep, 74 - * must not fail */ 75 66 #define CPU_BROKEN 0x000B /* CPU (unsigned)v did not die properly, 76 67 * perhaps due to preemption. */ 77 68 ··· 77 86 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN) 78 87 #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN) 79 88 #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN) 80 - #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN) 81 - #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN) 82 - 83 89 84 90 #ifdef CONFIG_SMP 85 91 extern bool cpuhp_tasks_frozen;
+132 -4
include/linux/cpuhotplug.h
··· 16 16 CPUHP_PERF_SUPERH, 17 17 CPUHP_X86_HPET_DEAD, 18 18 CPUHP_X86_APB_DEAD, 19 + CPUHP_VIRT_NET_DEAD, 20 + CPUHP_SLUB_DEAD, 21 + CPUHP_MM_WRITEBACK_DEAD, 22 + CPUHP_SOFTIRQ_DEAD, 23 + CPUHP_NET_MVNETA_DEAD, 24 + CPUHP_CPUIDLE_DEAD, 25 + CPUHP_ARM64_FPSIMD_DEAD, 26 + CPUHP_ARM_OMAP_WAKE_DEAD, 27 + CPUHP_IRQ_POLL_DEAD, 28 + CPUHP_BLOCK_SOFTIRQ_DEAD, 29 + CPUHP_VIRT_SCSI_DEAD, 30 + CPUHP_ACPI_CPUDRV_DEAD, 31 + CPUHP_S390_PFAULT_DEAD, 32 + CPUHP_BLK_MQ_DEAD, 19 33 CPUHP_WORKQUEUE_PREP, 20 34 CPUHP_POWER_NUMA_PREPARE, 21 35 CPUHP_HRTIMERS_PREPARE, 22 36 CPUHP_PROFILE_PREPARE, 23 37 CPUHP_X2APIC_PREPARE, 24 38 CPUHP_SMPCFD_PREPARE, 39 + CPUHP_RELAY_PREPARE, 40 + CPUHP_SLAB_PREPARE, 41 + CPUHP_MD_RAID5_PREPARE, 25 42 CPUHP_RCUTREE_PREP, 43 + CPUHP_CPUIDLE_COUPLED_PREPARE, 44 + CPUHP_POWERPC_PMAC_PREPARE, 45 + CPUHP_POWERPC_MMU_CTX_PREPARE, 26 46 CPUHP_NOTIFY_PREPARE, 47 + CPUHP_ARM_SHMOBILE_SCU_PREPARE, 48 + CPUHP_SH_SH3X_PREPARE, 49 + CPUHP_BLK_MQ_PREPARE, 27 50 CPUHP_TIMERS_DEAD, 51 + CPUHP_NOTF_ERR_INJ_PREPARE, 52 + CPUHP_MIPS_SOC_PREPARE, 28 53 CPUHP_BRINGUP_CPU, 29 54 CPUHP_AP_IDLE_DEAD, 30 55 CPUHP_AP_OFFLINE, ··· 97 72 CPUHP_AP_ARM64_ISNDEP_STARTING, 98 73 CPUHP_AP_SMPCFD_DYING, 99 74 CPUHP_AP_X86_TBOOT_DYING, 100 - CPUHP_AP_NOTIFY_STARTING, 101 75 CPUHP_AP_ONLINE, 102 76 CPUHP_TEARDOWN_CPU, 103 77 CPUHP_AP_ONLINE_IDLE, ··· 127 103 128 104 int __cpuhp_setup_state(enum cpuhp_state state, const char *name, bool invoke, 129 105 int (*startup)(unsigned int cpu), 130 - int (*teardown)(unsigned int cpu)); 106 + int (*teardown)(unsigned int cpu), bool multi_instance); 131 107 132 108 /** 133 109 * cpuhp_setup_state - Setup hotplug state callbacks with calling the callbacks ··· 144 120 int (*startup)(unsigned int cpu), 145 121 int (*teardown)(unsigned int cpu)) 146 122 { 147 - return __cpuhp_setup_state(state, name, true, startup, teardown); 123 + return __cpuhp_setup_state(state, name, true, startup, teardown, false); 148 124 } 149 125 150 126 /** ··· 163 139 int (*startup)(unsigned int cpu), 164 140 int (*teardown)(unsigned int cpu)) 165 141 { 166 - return __cpuhp_setup_state(state, name, false, startup, teardown); 142 + return __cpuhp_setup_state(state, name, false, startup, teardown, 143 + false); 144 + } 145 + 146 + /** 147 + * cpuhp_setup_state_multi - Add callbacks for multi state 148 + * @state: The state for which the calls are installed 149 + * @name: Name of the callback. 150 + * @startup: startup callback function 151 + * @teardown: teardown callback function 152 + * 153 + * Sets the internal multi_instance flag and prepares a state to work as a multi 154 + * instance callback. No callbacks are invoked at this point. The callbacks are 155 + * invoked once an instance for this state are registered via 156 + * @cpuhp_state_add_instance or @cpuhp_state_add_instance_nocalls. 157 + */ 158 + static inline int cpuhp_setup_state_multi(enum cpuhp_state state, 159 + const char *name, 160 + int (*startup)(unsigned int cpu, 161 + struct hlist_node *node), 162 + int (*teardown)(unsigned int cpu, 163 + struct hlist_node *node)) 164 + { 165 + return __cpuhp_setup_state(state, name, false, 166 + (void *) startup, 167 + (void *) teardown, true); 168 + } 169 + 170 + int __cpuhp_state_add_instance(enum cpuhp_state state, struct hlist_node *node, 171 + bool invoke); 172 + 173 + /** 174 + * cpuhp_state_add_instance - Add an instance for a state and invoke startup 175 + * callback. 176 + * @state: The state for which the instance is installed 177 + * @node: The node for this individual state. 178 + * 179 + * Installs the instance for the @state and invokes the startup callback on 180 + * the present cpus which have already reached the @state. The @state must have 181 + * been earlier marked as multi-instance by @cpuhp_setup_state_multi. 182 + */ 183 + static inline int cpuhp_state_add_instance(enum cpuhp_state state, 184 + struct hlist_node *node) 185 + { 186 + return __cpuhp_state_add_instance(state, node, true); 187 + } 188 + 189 + /** 190 + * cpuhp_state_add_instance_nocalls - Add an instance for a state without 191 + * invoking the startup callback. 192 + * @state: The state for which the instance is installed 193 + * @node: The node for this individual state. 194 + * 195 + * Installs the instance for the @state The @state must have been earlier 196 + * marked as multi-instance by @cpuhp_setup_state_multi. 197 + */ 198 + static inline int cpuhp_state_add_instance_nocalls(enum cpuhp_state state, 199 + struct hlist_node *node) 200 + { 201 + return __cpuhp_state_add_instance(state, node, false); 167 202 } 168 203 169 204 void __cpuhp_remove_state(enum cpuhp_state state, bool invoke); ··· 247 164 static inline void cpuhp_remove_state_nocalls(enum cpuhp_state state) 248 165 { 249 166 __cpuhp_remove_state(state, false); 167 + } 168 + 169 + /** 170 + * cpuhp_remove_multi_state - Remove hotplug multi state callback 171 + * @state: The state for which the calls are removed 172 + * 173 + * Removes the callback functions from a multi state. This is the reverse of 174 + * cpuhp_setup_state_multi(). All instances should have been removed before 175 + * invoking this function. 176 + */ 177 + static inline void cpuhp_remove_multi_state(enum cpuhp_state state) 178 + { 179 + __cpuhp_remove_state(state, false); 180 + } 181 + 182 + int __cpuhp_state_remove_instance(enum cpuhp_state state, 183 + struct hlist_node *node, bool invoke); 184 + 185 + /** 186 + * cpuhp_state_remove_instance - Remove hotplug instance from state and invoke 187 + * the teardown callback 188 + * @state: The state from which the instance is removed 189 + * @node: The node for this individual state. 190 + * 191 + * Removes the instance and invokes the teardown callback on the present cpus 192 + * which have already reached the @state. 193 + */ 194 + static inline int cpuhp_state_remove_instance(enum cpuhp_state state, 195 + struct hlist_node *node) 196 + { 197 + return __cpuhp_state_remove_instance(state, node, true); 198 + } 199 + 200 + /** 201 + * cpuhp_state_remove_instance_nocalls - Remove hotplug instance from state 202 + * without invoking the reatdown callback 203 + * @state: The state from which the instance is removed 204 + * @node: The node for this individual state. 205 + * 206 + * Removes the instance without invoking the teardown callback. 207 + */ 208 + static inline int cpuhp_state_remove_instance_nocalls(enum cpuhp_state state, 209 + struct hlist_node *node) 210 + { 211 + return __cpuhp_state_remove_instance(state, node, false); 250 212 } 251 213 252 214 #ifdef CONFIG_SMP
+1 -1
include/linux/padata.h
··· 151 151 * @flags: padata flags. 152 152 */ 153 153 struct padata_instance { 154 - struct notifier_block cpu_notifier; 154 + struct hlist_node node; 155 155 struct workqueue_struct *wq; 156 156 struct parallel_data *pd; 157 157 struct padata_cpumask cpumask;
+1 -1
include/linux/perf/arm_pmu.h
··· 116 116 DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS); 117 117 struct platform_device *plat_device; 118 118 struct pmu_hw_events __percpu *hw_events; 119 - struct list_head entry; 119 + struct hlist_node node; 120 120 struct notifier_block cpu_pm_nb; 121 121 /* the attr_groups array must be NULL-terminated */ 122 122 const struct attribute_group *attr_groups[ARMPMU_NR_ATTR_GROUPS + 1];
+16 -7
include/linux/relay.h
··· 19 19 #include <linux/fs.h> 20 20 #include <linux/poll.h> 21 21 #include <linux/kref.h> 22 + #include <linux/percpu.h> 22 23 23 24 /* 24 25 * Tracks changes to rchan/rchan_buf structs ··· 64 63 struct kref kref; /* channel refcount */ 65 64 void *private_data; /* for user-defined data */ 66 65 size_t last_toobig; /* tried to log event > subbuf size */ 67 - struct rchan_buf *buf[NR_CPUS]; /* per-cpu channel buffers */ 66 + struct rchan_buf ** __percpu buf; /* per-cpu channel buffers */ 68 67 int is_global; /* One global buffer ? */ 69 68 struct list_head list; /* for channel list */ 70 69 struct dentry *parent; /* parent dentry passed to open */ ··· 205 204 struct rchan_buf *buf; 206 205 207 206 local_irq_save(flags); 208 - buf = chan->buf[smp_processor_id()]; 207 + buf = *this_cpu_ptr(chan->buf); 209 208 if (unlikely(buf->offset + length > chan->subbuf_size)) 210 209 length = relay_switch_subbuf(buf, length); 211 210 memcpy(buf->data + buf->offset, data, length); ··· 231 230 { 232 231 struct rchan_buf *buf; 233 232 234 - buf = chan->buf[get_cpu()]; 233 + buf = *get_cpu_ptr(chan->buf); 235 234 if (unlikely(buf->offset + length > buf->chan->subbuf_size)) 236 235 length = relay_switch_subbuf(buf, length); 237 236 memcpy(buf->data + buf->offset, data, length); 238 237 buf->offset += length; 239 - put_cpu(); 238 + put_cpu_ptr(chan->buf); 240 239 } 241 240 242 241 /** ··· 252 251 */ 253 252 static inline void *relay_reserve(struct rchan *chan, size_t length) 254 253 { 255 - void *reserved; 256 - struct rchan_buf *buf = chan->buf[smp_processor_id()]; 254 + void *reserved = NULL; 255 + struct rchan_buf *buf = *get_cpu_ptr(chan->buf); 257 256 258 257 if (unlikely(buf->offset + length > buf->chan->subbuf_size)) { 259 258 length = relay_switch_subbuf(buf, length); 260 259 if (!length) 261 - return NULL; 260 + goto end; 262 261 } 263 262 reserved = buf->data + buf->offset; 264 263 buf->offset += length; 265 264 265 + end: 266 + put_cpu_ptr(chan->buf); 266 267 return reserved; 267 268 } 268 269 ··· 287 284 * exported relay file operations, kernel/relay.c 288 285 */ 289 286 extern const struct file_operations relay_file_operations; 287 + 288 + #ifdef CONFIG_RELAY 289 + int relay_prepare_cpu(unsigned int cpu); 290 + #else 291 + #define relay_prepare_cpu NULL 292 + #endif 290 293 291 294 #endif /* _LINUX_RELAY_H */ 292 295
+8
include/linux/slab.h
··· 650 650 unsigned int kmem_cache_size(struct kmem_cache *s); 651 651 void __init kmem_cache_init_late(void); 652 652 653 + #if defined(CONFIG_SMP) && defined(CONFIG_SLAB) 654 + int slab_prepare_cpu(unsigned int cpu); 655 + int slab_dead_cpu(unsigned int cpu); 656 + #else 657 + #define slab_prepare_cpu NULL 658 + #define slab_dead_cpu NULL 659 + #endif 660 + 653 661 #endif /* _LINUX_SLAB_H */
+28
include/trace/events/cpuhp.h
··· 33 33 __entry->cpu, __entry->target, __entry->idx, __entry->fun) 34 34 ); 35 35 36 + TRACE_EVENT(cpuhp_multi_enter, 37 + 38 + TP_PROTO(unsigned int cpu, 39 + int target, 40 + int idx, 41 + int (*fun)(unsigned int, struct hlist_node *), 42 + struct hlist_node *node), 43 + 44 + TP_ARGS(cpu, target, idx, fun, node), 45 + 46 + TP_STRUCT__entry( 47 + __field( unsigned int, cpu ) 48 + __field( int, target ) 49 + __field( int, idx ) 50 + __field( void *, fun ) 51 + ), 52 + 53 + TP_fast_assign( 54 + __entry->cpu = cpu; 55 + __entry->target = target; 56 + __entry->idx = idx; 57 + __entry->fun = fun; 58 + ), 59 + 60 + TP_printk("cpu: %04u target: %3d step: %3d (%pf)", 61 + __entry->cpu, __entry->target, __entry->idx, __entry->fun) 62 + ); 63 + 36 64 TRACE_EVENT(cpuhp_exit, 37 65 38 66 TP_PROTO(unsigned int cpu,
+330 -180
kernel/cpu.c
··· 23 23 #include <linux/tick.h> 24 24 #include <linux/irq.h> 25 25 #include <linux/smpboot.h> 26 + #include <linux/relay.h> 27 + #include <linux/slab.h> 26 28 27 29 #include <trace/events/power.h> 28 30 #define CREATE_TRACE_POINTS ··· 39 37 * @thread: Pointer to the hotplug thread 40 38 * @should_run: Thread should execute 41 39 * @rollback: Perform a rollback 42 - * @cb_stat: The state for a single callback (install/uninstall) 43 - * @cb: Single callback function (install/uninstall) 40 + * @single: Single callback invocation 41 + * @bringup: Single callback bringup or teardown selector 42 + * @cb_state: The state for a single callback (install/uninstall) 44 43 * @result: Result of the operation 45 44 * @done: Signal completion to the issuer of the task 46 45 */ ··· 52 49 struct task_struct *thread; 53 50 bool should_run; 54 51 bool rollback; 52 + bool single; 53 + bool bringup; 54 + struct hlist_node *node; 55 55 enum cpuhp_state cb_state; 56 - int (*cb)(unsigned int cpu); 57 56 int result; 58 57 struct completion done; 59 58 #endif ··· 73 68 * @cant_stop: Bringup/teardown can't be stopped at this step 74 69 */ 75 70 struct cpuhp_step { 76 - const char *name; 77 - int (*startup)(unsigned int cpu); 78 - int (*teardown)(unsigned int cpu); 79 - bool skip_onerr; 80 - bool cant_stop; 71 + const char *name; 72 + union { 73 + int (*single)(unsigned int cpu); 74 + int (*multi)(unsigned int cpu, 75 + struct hlist_node *node); 76 + } startup; 77 + union { 78 + int (*single)(unsigned int cpu); 79 + int (*multi)(unsigned int cpu, 80 + struct hlist_node *node); 81 + } teardown; 82 + struct hlist_head list; 83 + bool skip_onerr; 84 + bool cant_stop; 85 + bool multi_instance; 81 86 }; 82 87 83 88 static DEFINE_MUTEX(cpuhp_state_mutex); 84 89 static struct cpuhp_step cpuhp_bp_states[]; 85 90 static struct cpuhp_step cpuhp_ap_states[]; 86 91 92 + static bool cpuhp_is_ap_state(enum cpuhp_state state) 93 + { 94 + /* 95 + * The extra check for CPUHP_TEARDOWN_CPU is only for documentation 96 + * purposes as that state is handled explicitly in cpu_down. 97 + */ 98 + return state > CPUHP_BRINGUP_CPU && state != CPUHP_TEARDOWN_CPU; 99 + } 100 + 101 + static struct cpuhp_step *cpuhp_get_step(enum cpuhp_state state) 102 + { 103 + struct cpuhp_step *sp; 104 + 105 + sp = cpuhp_is_ap_state(state) ? cpuhp_ap_states : cpuhp_bp_states; 106 + return sp + state; 107 + } 108 + 87 109 /** 88 110 * cpuhp_invoke_callback _ Invoke the callbacks for a given state 89 111 * @cpu: The cpu for which the callback should be invoked 90 112 * @step: The step in the state machine 91 - * @cb: The callback function to invoke 113 + * @bringup: True if the bringup callback should be invoked 92 114 * 93 - * Called from cpu hotplug and from the state register machinery 115 + * Called from cpu hotplug and from the state register machinery. 94 116 */ 95 - static int cpuhp_invoke_callback(unsigned int cpu, enum cpuhp_state step, 96 - int (*cb)(unsigned int)) 117 + static int cpuhp_invoke_callback(unsigned int cpu, enum cpuhp_state state, 118 + bool bringup, struct hlist_node *node) 97 119 { 98 120 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu); 99 - int ret = 0; 121 + struct cpuhp_step *step = cpuhp_get_step(state); 122 + int (*cbm)(unsigned int cpu, struct hlist_node *node); 123 + int (*cb)(unsigned int cpu); 124 + int ret, cnt; 100 125 101 - if (cb) { 102 - trace_cpuhp_enter(cpu, st->target, step, cb); 126 + if (!step->multi_instance) { 127 + cb = bringup ? step->startup.single : step->teardown.single; 128 + if (!cb) 129 + return 0; 130 + trace_cpuhp_enter(cpu, st->target, state, cb); 103 131 ret = cb(cpu); 104 - trace_cpuhp_exit(cpu, st->state, step, ret); 132 + trace_cpuhp_exit(cpu, st->state, state, ret); 133 + return ret; 134 + } 135 + cbm = bringup ? step->startup.multi : step->teardown.multi; 136 + if (!cbm) 137 + return 0; 138 + 139 + /* Single invocation for instance add/remove */ 140 + if (node) { 141 + trace_cpuhp_multi_enter(cpu, st->target, state, cbm, node); 142 + ret = cbm(cpu, node); 143 + trace_cpuhp_exit(cpu, st->state, state, ret); 144 + return ret; 145 + } 146 + 147 + /* State transition. Invoke on all instances */ 148 + cnt = 0; 149 + hlist_for_each(node, &step->list) { 150 + trace_cpuhp_multi_enter(cpu, st->target, state, cbm, node); 151 + ret = cbm(cpu, node); 152 + trace_cpuhp_exit(cpu, st->state, state, ret); 153 + if (ret) 154 + goto err; 155 + cnt++; 156 + } 157 + return 0; 158 + err: 159 + /* Rollback the instances if one failed */ 160 + cbm = !bringup ? step->startup.multi : step->teardown.multi; 161 + if (!cbm) 162 + return ret; 163 + 164 + hlist_for_each(node, &step->list) { 165 + if (!cnt--) 166 + break; 167 + cbm(cpu, node); 105 168 } 106 169 return ret; 107 170 } ··· 333 260 } 334 261 EXPORT_SYMBOL_GPL(cpu_hotplug_disable); 335 262 263 + static void __cpu_hotplug_enable(void) 264 + { 265 + if (WARN_ONCE(!cpu_hotplug_disabled, "Unbalanced cpu hotplug enable\n")) 266 + return; 267 + cpu_hotplug_disabled--; 268 + } 269 + 336 270 void cpu_hotplug_enable(void) 337 271 { 338 272 cpu_maps_update_begin(); 339 - WARN_ON(--cpu_hotplug_disabled < 0); 273 + __cpu_hotplug_enable(); 340 274 cpu_maps_update_done(); 341 275 } 342 276 EXPORT_SYMBOL_GPL(cpu_hotplug_enable); ··· 410 330 return 0; 411 331 } 412 332 413 - static int notify_starting(unsigned int cpu) 414 - { 415 - cpu_notify(CPU_STARTING, cpu); 416 - return 0; 417 - } 418 - 419 333 static int bringup_wait_for_ap(unsigned int cpu) 420 334 { 421 335 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu); ··· 423 349 struct task_struct *idle = idle_thread_get(cpu); 424 350 int ret; 425 351 352 + /* 353 + * Some architectures have to walk the irq descriptors to 354 + * setup the vector space for the cpu which comes online. 355 + * Prevent irq alloc/free across the bringup. 356 + */ 357 + irq_lock_sparse(); 358 + 426 359 /* Arch-specific enabling code. */ 427 360 ret = __cpu_up(cpu, idle); 361 + irq_unlock_sparse(); 428 362 if (ret) { 429 363 cpu_notify(CPU_UP_CANCELED, cpu); 430 364 return ret; ··· 445 363 /* 446 364 * Hotplug state machine related functions 447 365 */ 448 - static void undo_cpu_down(unsigned int cpu, struct cpuhp_cpu_state *st, 449 - struct cpuhp_step *steps) 366 + static void undo_cpu_down(unsigned int cpu, struct cpuhp_cpu_state *st) 450 367 { 451 368 for (st->state++; st->state < st->target; st->state++) { 452 - struct cpuhp_step *step = steps + st->state; 369 + struct cpuhp_step *step = cpuhp_get_step(st->state); 453 370 454 371 if (!step->skip_onerr) 455 - cpuhp_invoke_callback(cpu, st->state, step->startup); 372 + cpuhp_invoke_callback(cpu, st->state, true, NULL); 456 373 } 457 374 } 458 375 459 376 static int cpuhp_down_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st, 460 - struct cpuhp_step *steps, enum cpuhp_state target) 377 + enum cpuhp_state target) 461 378 { 462 379 enum cpuhp_state prev_state = st->state; 463 380 int ret = 0; 464 381 465 382 for (; st->state > target; st->state--) { 466 - struct cpuhp_step *step = steps + st->state; 467 - 468 - ret = cpuhp_invoke_callback(cpu, st->state, step->teardown); 383 + ret = cpuhp_invoke_callback(cpu, st->state, false, NULL); 469 384 if (ret) { 470 385 st->target = prev_state; 471 - undo_cpu_down(cpu, st, steps); 386 + undo_cpu_down(cpu, st); 472 387 break; 473 388 } 474 389 } 475 390 return ret; 476 391 } 477 392 478 - static void undo_cpu_up(unsigned int cpu, struct cpuhp_cpu_state *st, 479 - struct cpuhp_step *steps) 393 + static void undo_cpu_up(unsigned int cpu, struct cpuhp_cpu_state *st) 480 394 { 481 395 for (st->state--; st->state > st->target; st->state--) { 482 - struct cpuhp_step *step = steps + st->state; 396 + struct cpuhp_step *step = cpuhp_get_step(st->state); 483 397 484 398 if (!step->skip_onerr) 485 - cpuhp_invoke_callback(cpu, st->state, step->teardown); 399 + cpuhp_invoke_callback(cpu, st->state, false, NULL); 486 400 } 487 401 } 488 402 489 403 static int cpuhp_up_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st, 490 - struct cpuhp_step *steps, enum cpuhp_state target) 404 + enum cpuhp_state target) 491 405 { 492 406 enum cpuhp_state prev_state = st->state; 493 407 int ret = 0; 494 408 495 409 while (st->state < target) { 496 - struct cpuhp_step *step; 497 - 498 410 st->state++; 499 - step = steps + st->state; 500 - ret = cpuhp_invoke_callback(cpu, st->state, step->startup); 411 + ret = cpuhp_invoke_callback(cpu, st->state, true, NULL); 501 412 if (ret) { 502 413 st->target = prev_state; 503 - undo_cpu_up(cpu, st, steps); 414 + undo_cpu_up(cpu, st); 504 415 break; 505 416 } 506 417 } ··· 522 447 { 523 448 enum cpuhp_state target = max((int)st->target, CPUHP_TEARDOWN_CPU); 524 449 525 - return cpuhp_down_callbacks(cpu, st, cpuhp_ap_states, target); 450 + return cpuhp_down_callbacks(cpu, st, target); 526 451 } 527 452 528 453 /* Execute the online startup callbacks. Used to be CPU_ONLINE */ 529 454 static int cpuhp_ap_online(unsigned int cpu, struct cpuhp_cpu_state *st) 530 455 { 531 - return cpuhp_up_callbacks(cpu, st, cpuhp_ap_states, st->target); 456 + return cpuhp_up_callbacks(cpu, st, st->target); 532 457 } 533 458 534 459 /* ··· 551 476 st->should_run = false; 552 477 553 478 /* Single callback invocation for [un]install ? */ 554 - if (st->cb) { 479 + if (st->single) { 555 480 if (st->cb_state < CPUHP_AP_ONLINE) { 556 481 local_irq_disable(); 557 - ret = cpuhp_invoke_callback(cpu, st->cb_state, st->cb); 482 + ret = cpuhp_invoke_callback(cpu, st->cb_state, 483 + st->bringup, st->node); 558 484 local_irq_enable(); 559 485 } else { 560 - ret = cpuhp_invoke_callback(cpu, st->cb_state, st->cb); 486 + ret = cpuhp_invoke_callback(cpu, st->cb_state, 487 + st->bringup, st->node); 561 488 } 562 489 } else if (st->rollback) { 563 490 BUG_ON(st->state < CPUHP_AP_ONLINE_IDLE); 564 491 565 - undo_cpu_down(cpu, st, cpuhp_ap_states); 492 + undo_cpu_down(cpu, st); 566 493 /* 567 494 * This is a momentary workaround to keep the notifier users 568 495 * happy. Will go away once we got rid of the notifiers. ··· 586 509 } 587 510 588 511 /* Invoke a single callback on a remote cpu */ 589 - static int cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state state, 590 - int (*cb)(unsigned int)) 512 + static int 513 + cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state state, bool bringup, 514 + struct hlist_node *node) 591 515 { 592 516 struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu); 593 517 ··· 600 522 * we invoke the thread function directly. 601 523 */ 602 524 if (!st->thread) 603 - return cpuhp_invoke_callback(cpu, state, cb); 525 + return cpuhp_invoke_callback(cpu, state, bringup, node); 604 526 605 527 st->cb_state = state; 606 - st->cb = cb; 528 + st->single = true; 529 + st->bringup = bringup; 530 + st->node = node; 531 + 607 532 /* 608 533 * Make sure the above stores are visible before should_run becomes 609 534 * true. Paired with the mb() above in cpuhp_thread_fun() ··· 622 541 static void __cpuhp_kick_ap_work(struct cpuhp_cpu_state *st) 623 542 { 624 543 st->result = 0; 625 - st->cb = NULL; 544 + st->single = false; 626 545 /* 627 546 * Make sure the above stores are visible before should_run becomes 628 547 * true. Paired with the mb() above in cpuhp_thread_fun() ··· 755 674 return err; 756 675 } 757 676 758 - static int notify_dying(unsigned int cpu) 759 - { 760 - cpu_notify(CPU_DYING, cpu); 761 - return 0; 762 - } 763 - 764 677 /* Take this CPU down. */ 765 678 static int take_cpu_down(void *_param) 766 679 { ··· 767 692 if (err < 0) 768 693 return err; 769 694 695 + /* 696 + * We get here while we are in CPUHP_TEARDOWN_CPU state and we must not 697 + * do this step again. 698 + */ 699 + WARN_ON(st->state != CPUHP_TEARDOWN_CPU); 700 + st->state--; 770 701 /* Invoke the former CPU_DYING callbacks */ 771 - for (; st->state > target; st->state--) { 772 - struct cpuhp_step *step = cpuhp_ap_states + st->state; 702 + for (; st->state > target; st->state--) 703 + cpuhp_invoke_callback(cpu, st->state, false, NULL); 773 704 774 - cpuhp_invoke_callback(cpu, st->state, step->teardown); 775 - } 776 705 /* Give up timekeeping duties */ 777 706 tick_handover_do_timer(); 778 707 /* Park the stopper thread */ ··· 813 734 BUG_ON(cpu_online(cpu)); 814 735 815 736 /* 816 - * The migration_call() CPU_DYING callback will have removed all 737 + * The CPUHP_AP_SCHED_MIGRATE_DYING callback will have removed all 817 738 * runnable tasks from the cpu, there's only the idle task left now 818 739 * that the migration thread is done doing the stop_machine thing. 819 740 * ··· 866 787 #define notify_down_prepare NULL 867 788 #define takedown_cpu NULL 868 789 #define notify_dead NULL 869 - #define notify_dying NULL 870 790 #endif 871 791 872 792 #ifdef CONFIG_HOTPLUG_CPU ··· 914 836 * The AP brought itself down to CPUHP_TEARDOWN_CPU. So we need 915 837 * to do the further cleanups. 916 838 */ 917 - ret = cpuhp_down_callbacks(cpu, st, cpuhp_bp_states, target); 839 + ret = cpuhp_down_callbacks(cpu, st, target); 918 840 if (ret && st->state > CPUHP_TEARDOWN_CPU && st->state < prev_state) { 919 841 st->target = prev_state; 920 842 st->rollback = true; ··· 955 877 #endif /*CONFIG_HOTPLUG_CPU*/ 956 878 957 879 /** 958 - * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers 880 + * notify_cpu_starting(cpu) - Invoke the callbacks on the starting CPU 959 881 * @cpu: cpu that just started 960 882 * 961 - * This function calls the cpu_chain notifiers with CPU_STARTING. 962 883 * It must be called by the arch code on the new cpu, before the new cpu 963 884 * enables interrupts and before the "boot" cpu returns from __cpu_up(). 964 885 */ ··· 968 891 969 892 rcu_cpu_starting(cpu); /* Enables RCU usage on this CPU. */ 970 893 while (st->state < target) { 971 - struct cpuhp_step *step; 972 - 973 894 st->state++; 974 - step = cpuhp_ap_states + st->state; 975 - cpuhp_invoke_callback(cpu, st->state, step->startup); 895 + cpuhp_invoke_callback(cpu, st->state, true, NULL); 976 896 } 977 897 } 978 898 ··· 1054 980 * responsible for bringing it up to the target state. 1055 981 */ 1056 982 target = min((int)target, CPUHP_BRINGUP_CPU); 1057 - ret = cpuhp_up_callbacks(cpu, st, cpuhp_bp_states, target); 983 + ret = cpuhp_up_callbacks(cpu, st, target); 1058 984 out: 1059 985 cpu_hotplug_done(); 1060 986 return ret; ··· 1157 1083 1158 1084 /* Allow everyone to use the CPU hotplug again */ 1159 1085 cpu_maps_update_begin(); 1160 - WARN_ON(--cpu_hotplug_disabled < 0); 1086 + __cpu_hotplug_enable(); 1161 1087 if (cpumask_empty(frozen_cpus)) 1162 1088 goto out; 1163 1089 ··· 1246 1172 static struct cpuhp_step cpuhp_bp_states[] = { 1247 1173 [CPUHP_OFFLINE] = { 1248 1174 .name = "offline", 1249 - .startup = NULL, 1250 - .teardown = NULL, 1175 + .startup.single = NULL, 1176 + .teardown.single = NULL, 1251 1177 }, 1252 1178 #ifdef CONFIG_SMP 1253 1179 [CPUHP_CREATE_THREADS]= { 1254 - .name = "threads:create", 1255 - .startup = smpboot_create_threads, 1256 - .teardown = NULL, 1180 + .name = "threads:prepare", 1181 + .startup.single = smpboot_create_threads, 1182 + .teardown.single = NULL, 1257 1183 .cant_stop = true, 1258 1184 }, 1259 1185 [CPUHP_PERF_PREPARE] = { 1260 - .name = "perf prepare", 1261 - .startup = perf_event_init_cpu, 1262 - .teardown = perf_event_exit_cpu, 1186 + .name = "perf:prepare", 1187 + .startup.single = perf_event_init_cpu, 1188 + .teardown.single = perf_event_exit_cpu, 1263 1189 }, 1264 1190 [CPUHP_WORKQUEUE_PREP] = { 1265 - .name = "workqueue prepare", 1266 - .startup = workqueue_prepare_cpu, 1267 - .teardown = NULL, 1191 + .name = "workqueue:prepare", 1192 + .startup.single = workqueue_prepare_cpu, 1193 + .teardown.single = NULL, 1268 1194 }, 1269 1195 [CPUHP_HRTIMERS_PREPARE] = { 1270 - .name = "hrtimers prepare", 1271 - .startup = hrtimers_prepare_cpu, 1272 - .teardown = hrtimers_dead_cpu, 1196 + .name = "hrtimers:prepare", 1197 + .startup.single = hrtimers_prepare_cpu, 1198 + .teardown.single = hrtimers_dead_cpu, 1273 1199 }, 1274 1200 [CPUHP_SMPCFD_PREPARE] = { 1275 - .name = "SMPCFD prepare", 1276 - .startup = smpcfd_prepare_cpu, 1277 - .teardown = smpcfd_dead_cpu, 1201 + .name = "smpcfd:prepare", 1202 + .startup.single = smpcfd_prepare_cpu, 1203 + .teardown.single = smpcfd_dead_cpu, 1204 + }, 1205 + [CPUHP_RELAY_PREPARE] = { 1206 + .name = "relay:prepare", 1207 + .startup.single = relay_prepare_cpu, 1208 + .teardown.single = NULL, 1209 + }, 1210 + [CPUHP_SLAB_PREPARE] = { 1211 + .name = "slab:prepare", 1212 + .startup.single = slab_prepare_cpu, 1213 + .teardown.single = slab_dead_cpu, 1278 1214 }, 1279 1215 [CPUHP_RCUTREE_PREP] = { 1280 - .name = "RCU-tree prepare", 1281 - .startup = rcutree_prepare_cpu, 1282 - .teardown = rcutree_dead_cpu, 1216 + .name = "RCU/tree:prepare", 1217 + .startup.single = rcutree_prepare_cpu, 1218 + .teardown.single = rcutree_dead_cpu, 1283 1219 }, 1284 1220 /* 1285 1221 * Preparatory and dead notifiers. Will be replaced once the notifiers ··· 1297 1213 */ 1298 1214 [CPUHP_NOTIFY_PREPARE] = { 1299 1215 .name = "notify:prepare", 1300 - .startup = notify_prepare, 1301 - .teardown = notify_dead, 1216 + .startup.single = notify_prepare, 1217 + .teardown.single = notify_dead, 1302 1218 .skip_onerr = true, 1303 1219 .cant_stop = true, 1304 1220 }, ··· 1308 1224 * otherwise a RCU stall occurs. 1309 1225 */ 1310 1226 [CPUHP_TIMERS_DEAD] = { 1311 - .name = "timers dead", 1312 - .startup = NULL, 1313 - .teardown = timers_dead_cpu, 1227 + .name = "timers:dead", 1228 + .startup.single = NULL, 1229 + .teardown.single = timers_dead_cpu, 1314 1230 }, 1315 1231 /* Kicks the plugged cpu into life */ 1316 1232 [CPUHP_BRINGUP_CPU] = { 1317 1233 .name = "cpu:bringup", 1318 - .startup = bringup_cpu, 1319 - .teardown = NULL, 1234 + .startup.single = bringup_cpu, 1235 + .teardown.single = NULL, 1320 1236 .cant_stop = true, 1321 1237 }, 1322 1238 [CPUHP_AP_SMPCFD_DYING] = { 1323 - .startup = NULL, 1324 - .teardown = smpcfd_dying_cpu, 1239 + .name = "smpcfd:dying", 1240 + .startup.single = NULL, 1241 + .teardown.single = smpcfd_dying_cpu, 1325 1242 }, 1326 1243 /* 1327 1244 * Handled on controll processor until the plugged processor manages ··· 1330 1245 */ 1331 1246 [CPUHP_TEARDOWN_CPU] = { 1332 1247 .name = "cpu:teardown", 1333 - .startup = NULL, 1334 - .teardown = takedown_cpu, 1248 + .startup.single = NULL, 1249 + .teardown.single = takedown_cpu, 1335 1250 .cant_stop = true, 1336 1251 }, 1337 1252 #else ··· 1357 1272 /* First state is scheduler control. Interrupts are disabled */ 1358 1273 [CPUHP_AP_SCHED_STARTING] = { 1359 1274 .name = "sched:starting", 1360 - .startup = sched_cpu_starting, 1361 - .teardown = sched_cpu_dying, 1275 + .startup.single = sched_cpu_starting, 1276 + .teardown.single = sched_cpu_dying, 1362 1277 }, 1363 1278 [CPUHP_AP_RCUTREE_DYING] = { 1364 - .startup = NULL, 1365 - .teardown = rcutree_dying_cpu, 1366 - }, 1367 - /* 1368 - * Low level startup/teardown notifiers. Run with interrupts 1369 - * disabled. Will be removed once the notifiers are converted to 1370 - * states. 1371 - */ 1372 - [CPUHP_AP_NOTIFY_STARTING] = { 1373 - .name = "notify:starting", 1374 - .startup = notify_starting, 1375 - .teardown = notify_dying, 1376 - .skip_onerr = true, 1377 - .cant_stop = true, 1279 + .name = "RCU/tree:dying", 1280 + .startup.single = NULL, 1281 + .teardown.single = rcutree_dying_cpu, 1378 1282 }, 1379 1283 /* Entry state on starting. Interrupts enabled from here on. Transient 1380 1284 * state for synchronsization */ ··· 1372 1298 }, 1373 1299 /* Handle smpboot threads park/unpark */ 1374 1300 [CPUHP_AP_SMPBOOT_THREADS] = { 1375 - .name = "smpboot:threads", 1376 - .startup = smpboot_unpark_threads, 1377 - .teardown = NULL, 1301 + .name = "smpboot/threads:online", 1302 + .startup.single = smpboot_unpark_threads, 1303 + .teardown.single = NULL, 1378 1304 }, 1379 1305 [CPUHP_AP_PERF_ONLINE] = { 1380 - .name = "perf online", 1381 - .startup = perf_event_init_cpu, 1382 - .teardown = perf_event_exit_cpu, 1306 + .name = "perf:online", 1307 + .startup.single = perf_event_init_cpu, 1308 + .teardown.single = perf_event_exit_cpu, 1383 1309 }, 1384 1310 [CPUHP_AP_WORKQUEUE_ONLINE] = { 1385 - .name = "workqueue online", 1386 - .startup = workqueue_online_cpu, 1387 - .teardown = workqueue_offline_cpu, 1311 + .name = "workqueue:online", 1312 + .startup.single = workqueue_online_cpu, 1313 + .teardown.single = workqueue_offline_cpu, 1388 1314 }, 1389 1315 [CPUHP_AP_RCUTREE_ONLINE] = { 1390 - .name = "RCU-tree online", 1391 - .startup = rcutree_online_cpu, 1392 - .teardown = rcutree_offline_cpu, 1316 + .name = "RCU/tree:online", 1317 + .startup.single = rcutree_online_cpu, 1318 + .teardown.single = rcutree_offline_cpu, 1393 1319 }, 1394 1320 1395 1321 /* ··· 1398 1324 */ 1399 1325 [CPUHP_AP_NOTIFY_ONLINE] = { 1400 1326 .name = "notify:online", 1401 - .startup = notify_online, 1402 - .teardown = notify_down_prepare, 1327 + .startup.single = notify_online, 1328 + .teardown.single = notify_down_prepare, 1403 1329 .skip_onerr = true, 1404 1330 }, 1405 1331 #endif ··· 1411 1337 /* Last state is scheduler control setting the cpu active */ 1412 1338 [CPUHP_AP_ACTIVE] = { 1413 1339 .name = "sched:active", 1414 - .startup = sched_cpu_activate, 1415 - .teardown = sched_cpu_deactivate, 1340 + .startup.single = sched_cpu_activate, 1341 + .teardown.single = sched_cpu_deactivate, 1416 1342 }, 1417 1343 #endif 1418 1344 1419 1345 /* CPU is fully up and running. */ 1420 1346 [CPUHP_ONLINE] = { 1421 1347 .name = "online", 1422 - .startup = NULL, 1423 - .teardown = NULL, 1348 + .startup.single = NULL, 1349 + .teardown.single = NULL, 1424 1350 }, 1425 1351 }; 1426 1352 ··· 1432 1358 return 0; 1433 1359 } 1434 1360 1435 - static bool cpuhp_is_ap_state(enum cpuhp_state state) 1436 - { 1437 - /* 1438 - * The extra check for CPUHP_TEARDOWN_CPU is only for documentation 1439 - * purposes as that state is handled explicitely in cpu_down. 1440 - */ 1441 - return state > CPUHP_BRINGUP_CPU && state != CPUHP_TEARDOWN_CPU; 1442 - } 1443 - 1444 - static struct cpuhp_step *cpuhp_get_step(enum cpuhp_state state) 1445 - { 1446 - struct cpuhp_step *sp; 1447 - 1448 - sp = cpuhp_is_ap_state(state) ? cpuhp_ap_states : cpuhp_bp_states; 1449 - return sp + state; 1450 - } 1451 - 1452 1361 static void cpuhp_store_callbacks(enum cpuhp_state state, 1453 1362 const char *name, 1454 1363 int (*startup)(unsigned int cpu), 1455 - int (*teardown)(unsigned int cpu)) 1364 + int (*teardown)(unsigned int cpu), 1365 + bool multi_instance) 1456 1366 { 1457 1367 /* (Un)Install the callbacks for further cpu hotplug operations */ 1458 1368 struct cpuhp_step *sp; 1459 1369 1460 1370 mutex_lock(&cpuhp_state_mutex); 1461 1371 sp = cpuhp_get_step(state); 1462 - sp->startup = startup; 1463 - sp->teardown = teardown; 1372 + sp->startup.single = startup; 1373 + sp->teardown.single = teardown; 1464 1374 sp->name = name; 1375 + sp->multi_instance = multi_instance; 1376 + INIT_HLIST_HEAD(&sp->list); 1465 1377 mutex_unlock(&cpuhp_state_mutex); 1466 1378 } 1467 1379 1468 1380 static void *cpuhp_get_teardown_cb(enum cpuhp_state state) 1469 1381 { 1470 - return cpuhp_get_step(state)->teardown; 1382 + return cpuhp_get_step(state)->teardown.single; 1471 1383 } 1472 1384 1473 1385 /* 1474 1386 * Call the startup/teardown function for a step either on the AP or 1475 1387 * on the current CPU. 1476 1388 */ 1477 - static int cpuhp_issue_call(int cpu, enum cpuhp_state state, 1478 - int (*cb)(unsigned int), bool bringup) 1389 + static int cpuhp_issue_call(int cpu, enum cpuhp_state state, bool bringup, 1390 + struct hlist_node *node) 1479 1391 { 1392 + struct cpuhp_step *sp = cpuhp_get_step(state); 1480 1393 int ret; 1481 1394 1482 - if (!cb) 1395 + if ((bringup && !sp->startup.single) || 1396 + (!bringup && !sp->teardown.single)) 1483 1397 return 0; 1484 1398 /* 1485 1399 * The non AP bound callbacks can fail on bringup. On teardown ··· 1475 1413 */ 1476 1414 #ifdef CONFIG_SMP 1477 1415 if (cpuhp_is_ap_state(state)) 1478 - ret = cpuhp_invoke_ap_callback(cpu, state, cb); 1416 + ret = cpuhp_invoke_ap_callback(cpu, state, bringup, node); 1479 1417 else 1480 - ret = cpuhp_invoke_callback(cpu, state, cb); 1418 + ret = cpuhp_invoke_callback(cpu, state, bringup, node); 1481 1419 #else 1482 - ret = cpuhp_invoke_callback(cpu, state, cb); 1420 + ret = cpuhp_invoke_callback(cpu, state, bringup, node); 1483 1421 #endif 1484 1422 BUG_ON(ret && !bringup); 1485 1423 return ret; ··· 1491 1429 * Note: The teardown callbacks for rollback are not allowed to fail! 1492 1430 */ 1493 1431 static void cpuhp_rollback_install(int failedcpu, enum cpuhp_state state, 1494 - int (*teardown)(unsigned int cpu)) 1432 + struct hlist_node *node) 1495 1433 { 1496 1434 int cpu; 1497 - 1498 - if (!teardown) 1499 - return; 1500 1435 1501 1436 /* Roll back the already executed steps on the other cpus */ 1502 1437 for_each_present_cpu(cpu) { ··· 1505 1446 1506 1447 /* Did we invoke the startup call on that cpu ? */ 1507 1448 if (cpustate >= state) 1508 - cpuhp_issue_call(cpu, state, teardown, false); 1449 + cpuhp_issue_call(cpu, state, false, node); 1509 1450 } 1510 1451 } 1511 1452 ··· 1532 1473 return -ENOSPC; 1533 1474 } 1534 1475 1476 + int __cpuhp_state_add_instance(enum cpuhp_state state, struct hlist_node *node, 1477 + bool invoke) 1478 + { 1479 + struct cpuhp_step *sp; 1480 + int cpu; 1481 + int ret; 1482 + 1483 + sp = cpuhp_get_step(state); 1484 + if (sp->multi_instance == false) 1485 + return -EINVAL; 1486 + 1487 + get_online_cpus(); 1488 + 1489 + if (!invoke || !sp->startup.multi) 1490 + goto add_node; 1491 + 1492 + /* 1493 + * Try to call the startup callback for each present cpu 1494 + * depending on the hotplug state of the cpu. 1495 + */ 1496 + for_each_present_cpu(cpu) { 1497 + struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu); 1498 + int cpustate = st->state; 1499 + 1500 + if (cpustate < state) 1501 + continue; 1502 + 1503 + ret = cpuhp_issue_call(cpu, state, true, node); 1504 + if (ret) { 1505 + if (sp->teardown.multi) 1506 + cpuhp_rollback_install(cpu, state, node); 1507 + goto err; 1508 + } 1509 + } 1510 + add_node: 1511 + ret = 0; 1512 + mutex_lock(&cpuhp_state_mutex); 1513 + hlist_add_head(node, &sp->list); 1514 + mutex_unlock(&cpuhp_state_mutex); 1515 + 1516 + err: 1517 + put_online_cpus(); 1518 + return ret; 1519 + } 1520 + EXPORT_SYMBOL_GPL(__cpuhp_state_add_instance); 1521 + 1535 1522 /** 1536 1523 * __cpuhp_setup_state - Setup the callbacks for an hotplug machine state 1537 1524 * @state: The state to setup ··· 1591 1486 int __cpuhp_setup_state(enum cpuhp_state state, 1592 1487 const char *name, bool invoke, 1593 1488 int (*startup)(unsigned int cpu), 1594 - int (*teardown)(unsigned int cpu)) 1489 + int (*teardown)(unsigned int cpu), 1490 + bool multi_instance) 1595 1491 { 1596 1492 int cpu, ret = 0; 1597 1493 int dyn_state = 0; ··· 1611 1505 state = ret; 1612 1506 } 1613 1507 1614 - cpuhp_store_callbacks(state, name, startup, teardown); 1508 + cpuhp_store_callbacks(state, name, startup, teardown, multi_instance); 1615 1509 1616 1510 if (!invoke || !startup) 1617 1511 goto out; ··· 1627 1521 if (cpustate < state) 1628 1522 continue; 1629 1523 1630 - ret = cpuhp_issue_call(cpu, state, startup, true); 1524 + ret = cpuhp_issue_call(cpu, state, true, NULL); 1631 1525 if (ret) { 1632 - cpuhp_rollback_install(cpu, state, teardown); 1633 - cpuhp_store_callbacks(state, NULL, NULL, NULL); 1526 + if (teardown) 1527 + cpuhp_rollback_install(cpu, state, NULL); 1528 + cpuhp_store_callbacks(state, NULL, NULL, NULL, false); 1634 1529 goto out; 1635 1530 } 1636 1531 } ··· 1643 1536 } 1644 1537 EXPORT_SYMBOL(__cpuhp_setup_state); 1645 1538 1539 + int __cpuhp_state_remove_instance(enum cpuhp_state state, 1540 + struct hlist_node *node, bool invoke) 1541 + { 1542 + struct cpuhp_step *sp = cpuhp_get_step(state); 1543 + int cpu; 1544 + 1545 + BUG_ON(cpuhp_cb_check(state)); 1546 + 1547 + if (!sp->multi_instance) 1548 + return -EINVAL; 1549 + 1550 + get_online_cpus(); 1551 + if (!invoke || !cpuhp_get_teardown_cb(state)) 1552 + goto remove; 1553 + /* 1554 + * Call the teardown callback for each present cpu depending 1555 + * on the hotplug state of the cpu. This function is not 1556 + * allowed to fail currently! 1557 + */ 1558 + for_each_present_cpu(cpu) { 1559 + struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu); 1560 + int cpustate = st->state; 1561 + 1562 + if (cpustate >= state) 1563 + cpuhp_issue_call(cpu, state, false, node); 1564 + } 1565 + 1566 + remove: 1567 + mutex_lock(&cpuhp_state_mutex); 1568 + hlist_del(node); 1569 + mutex_unlock(&cpuhp_state_mutex); 1570 + put_online_cpus(); 1571 + 1572 + return 0; 1573 + } 1574 + EXPORT_SYMBOL_GPL(__cpuhp_state_remove_instance); 1646 1575 /** 1647 1576 * __cpuhp_remove_state - Remove the callbacks for an hotplug machine state 1648 1577 * @state: The state to remove ··· 1690 1547 */ 1691 1548 void __cpuhp_remove_state(enum cpuhp_state state, bool invoke) 1692 1549 { 1693 - int (*teardown)(unsigned int cpu) = cpuhp_get_teardown_cb(state); 1550 + struct cpuhp_step *sp = cpuhp_get_step(state); 1694 1551 int cpu; 1695 1552 1696 1553 BUG_ON(cpuhp_cb_check(state)); 1697 1554 1698 1555 get_online_cpus(); 1699 1556 1700 - if (!invoke || !teardown) 1557 + if (sp->multi_instance) { 1558 + WARN(!hlist_empty(&sp->list), 1559 + "Error: Removing state %d which has instances left.\n", 1560 + state); 1561 + goto remove; 1562 + } 1563 + 1564 + if (!invoke || !cpuhp_get_teardown_cb(state)) 1701 1565 goto remove; 1702 1566 1703 1567 /* ··· 1717 1567 int cpustate = st->state; 1718 1568 1719 1569 if (cpustate >= state) 1720 - cpuhp_issue_call(cpu, state, teardown, false); 1570 + cpuhp_issue_call(cpu, state, false, NULL); 1721 1571 } 1722 1572 remove: 1723 - cpuhp_store_callbacks(state, NULL, NULL, NULL); 1573 + cpuhp_store_callbacks(state, NULL, NULL, NULL, false); 1724 1574 put_online_cpus(); 1725 1575 } 1726 1576 EXPORT_SYMBOL(__cpuhp_remove_state);
+52 -40
kernel/padata.c
··· 30 30 #include <linux/slab.h> 31 31 #include <linux/sysfs.h> 32 32 #include <linux/rcupdate.h> 33 + #include <linux/module.h> 33 34 34 35 #define MAX_OBJ_NUM 1000 35 36 ··· 770 769 cpumask_test_cpu(cpu, pinst->cpumask.cbcpu); 771 770 } 772 771 773 - 774 - static int padata_cpu_callback(struct notifier_block *nfb, 775 - unsigned long action, void *hcpu) 772 + static int padata_cpu_online(unsigned int cpu, struct hlist_node *node) 776 773 { 777 - int err; 778 774 struct padata_instance *pinst; 779 - int cpu = (unsigned long)hcpu; 775 + int ret; 780 776 781 - pinst = container_of(nfb, struct padata_instance, cpu_notifier); 777 + pinst = hlist_entry_safe(node, struct padata_instance, node); 778 + if (!pinst_has_cpu(pinst, cpu)) 779 + return 0; 782 780 783 - switch (action) { 784 - case CPU_ONLINE: 785 - case CPU_ONLINE_FROZEN: 786 - case CPU_DOWN_FAILED: 787 - case CPU_DOWN_FAILED_FROZEN: 788 - if (!pinst_has_cpu(pinst, cpu)) 789 - break; 790 - mutex_lock(&pinst->lock); 791 - err = __padata_add_cpu(pinst, cpu); 792 - mutex_unlock(&pinst->lock); 793 - if (err) 794 - return notifier_from_errno(err); 795 - break; 796 - 797 - case CPU_DOWN_PREPARE: 798 - case CPU_DOWN_PREPARE_FROZEN: 799 - case CPU_UP_CANCELED: 800 - case CPU_UP_CANCELED_FROZEN: 801 - if (!pinst_has_cpu(pinst, cpu)) 802 - break; 803 - mutex_lock(&pinst->lock); 804 - err = __padata_remove_cpu(pinst, cpu); 805 - mutex_unlock(&pinst->lock); 806 - if (err) 807 - return notifier_from_errno(err); 808 - break; 809 - } 810 - 811 - return NOTIFY_OK; 781 + mutex_lock(&pinst->lock); 782 + ret = __padata_add_cpu(pinst, cpu); 783 + mutex_unlock(&pinst->lock); 784 + return ret; 812 785 } 786 + 787 + static int padata_cpu_prep_down(unsigned int cpu, struct hlist_node *node) 788 + { 789 + struct padata_instance *pinst; 790 + int ret; 791 + 792 + pinst = hlist_entry_safe(node, struct padata_instance, node); 793 + if (!pinst_has_cpu(pinst, cpu)) 794 + return 0; 795 + 796 + mutex_lock(&pinst->lock); 797 + ret = __padata_remove_cpu(pinst, cpu); 798 + mutex_unlock(&pinst->lock); 799 + return ret; 800 + } 801 + 802 + static enum cpuhp_state hp_online; 813 803 #endif 814 804 815 805 static void __padata_free(struct padata_instance *pinst) 816 806 { 817 807 #ifdef CONFIG_HOTPLUG_CPU 818 - unregister_hotcpu_notifier(&pinst->cpu_notifier); 808 + cpuhp_state_remove_instance_nocalls(hp_online, &pinst->node); 819 809 #endif 820 810 821 811 padata_stop(pinst); ··· 1004 1012 mutex_init(&pinst->lock); 1005 1013 1006 1014 #ifdef CONFIG_HOTPLUG_CPU 1007 - pinst->cpu_notifier.notifier_call = padata_cpu_callback; 1008 - pinst->cpu_notifier.priority = 0; 1009 - register_hotcpu_notifier(&pinst->cpu_notifier); 1015 + cpuhp_state_add_instance_nocalls(hp_online, &pinst->node); 1010 1016 #endif 1011 - 1012 1017 return pinst; 1013 1018 1014 1019 err_free_masks: ··· 1028 1039 kobject_put(&pinst->kobj); 1029 1040 } 1030 1041 EXPORT_SYMBOL(padata_free); 1042 + 1043 + #ifdef CONFIG_HOTPLUG_CPU 1044 + 1045 + static __init int padata_driver_init(void) 1046 + { 1047 + int ret; 1048 + 1049 + ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "padata:online", 1050 + padata_cpu_online, 1051 + padata_cpu_prep_down); 1052 + if (ret < 0) 1053 + return ret; 1054 + hp_online = ret; 1055 + return 0; 1056 + } 1057 + module_init(padata_driver_init); 1058 + 1059 + static __exit void padata_driver_exit(void) 1060 + { 1061 + cpuhp_remove_multi_state(hp_online); 1062 + } 1063 + module_exit(padata_driver_exit); 1064 + #endif
+51 -73
kernel/relay.c
··· 214 214 __free_page(buf->page_array[i]); 215 215 relay_free_page_array(buf->page_array); 216 216 } 217 - chan->buf[buf->cpu] = NULL; 217 + *per_cpu_ptr(chan->buf, buf->cpu) = NULL; 218 218 kfree(buf->padding); 219 219 kfree(buf); 220 220 kref_put(&chan->kref, relay_destroy_channel); ··· 382 382 */ 383 383 void relay_reset(struct rchan *chan) 384 384 { 385 + struct rchan_buf *buf; 385 386 unsigned int i; 386 387 387 388 if (!chan) 388 389 return; 389 390 390 - if (chan->is_global && chan->buf[0]) { 391 - __relay_reset(chan->buf[0], 0); 391 + if (chan->is_global && (buf = *per_cpu_ptr(chan->buf, 0))) { 392 + __relay_reset(buf, 0); 392 393 return; 393 394 } 394 395 395 396 mutex_lock(&relay_channels_mutex); 396 397 for_each_possible_cpu(i) 397 - if (chan->buf[i]) 398 - __relay_reset(chan->buf[i], 0); 398 + if ((buf = *per_cpu_ptr(chan->buf, i))) 399 + __relay_reset(buf, 0); 399 400 mutex_unlock(&relay_channels_mutex); 400 401 } 401 402 EXPORT_SYMBOL_GPL(relay_reset); ··· 441 440 struct dentry *dentry; 442 441 443 442 if (chan->is_global) 444 - return chan->buf[0]; 443 + return *per_cpu_ptr(chan->buf, 0); 445 444 446 445 buf = relay_create_buf(chan); 447 446 if (!buf) ··· 465 464 __relay_reset(buf, 1); 466 465 467 466 if(chan->is_global) { 468 - chan->buf[0] = buf; 467 + *per_cpu_ptr(chan->buf, 0) = buf; 469 468 buf->cpu = 0; 470 469 } 471 470 ··· 513 512 chan->cb = cb; 514 513 } 515 514 516 - /** 517 - * relay_hotcpu_callback - CPU hotplug callback 518 - * @nb: notifier block 519 - * @action: hotplug action to take 520 - * @hcpu: CPU number 521 - * 522 - * Returns the success/failure of the operation. (%NOTIFY_OK, %NOTIFY_BAD) 523 - */ 524 - static int relay_hotcpu_callback(struct notifier_block *nb, 525 - unsigned long action, 526 - void *hcpu) 515 + int relay_prepare_cpu(unsigned int cpu) 527 516 { 528 - unsigned int hotcpu = (unsigned long)hcpu; 529 517 struct rchan *chan; 518 + struct rchan_buf *buf; 530 519 531 - switch(action) { 532 - case CPU_UP_PREPARE: 533 - case CPU_UP_PREPARE_FROZEN: 534 - mutex_lock(&relay_channels_mutex); 535 - list_for_each_entry(chan, &relay_channels, list) { 536 - if (chan->buf[hotcpu]) 537 - continue; 538 - chan->buf[hotcpu] = relay_open_buf(chan, hotcpu); 539 - if(!chan->buf[hotcpu]) { 540 - printk(KERN_ERR 541 - "relay_hotcpu_callback: cpu %d buffer " 542 - "creation failed\n", hotcpu); 543 - mutex_unlock(&relay_channels_mutex); 544 - return notifier_from_errno(-ENOMEM); 545 - } 520 + mutex_lock(&relay_channels_mutex); 521 + list_for_each_entry(chan, &relay_channels, list) { 522 + if ((buf = *per_cpu_ptr(chan->buf, cpu))) 523 + continue; 524 + buf = relay_open_buf(chan, cpu); 525 + if (!buf) { 526 + pr_err("relay: cpu %d buffer creation failed\n", cpu); 527 + mutex_unlock(&relay_channels_mutex); 528 + return -ENOMEM; 546 529 } 547 - mutex_unlock(&relay_channels_mutex); 548 - break; 549 - case CPU_DEAD: 550 - case CPU_DEAD_FROZEN: 551 - /* No need to flush the cpu : will be flushed upon 552 - * final relay_flush() call. */ 553 - break; 530 + *per_cpu_ptr(chan->buf, cpu) = buf; 554 531 } 555 - return NOTIFY_OK; 532 + mutex_unlock(&relay_channels_mutex); 533 + return 0; 556 534 } 557 535 558 536 /** ··· 563 583 { 564 584 unsigned int i; 565 585 struct rchan *chan; 586 + struct rchan_buf *buf; 566 587 567 588 if (!(subbuf_size && n_subbufs)) 568 589 return NULL; ··· 574 593 if (!chan) 575 594 return NULL; 576 595 596 + chan->buf = alloc_percpu(struct rchan_buf *); 577 597 chan->version = RELAYFS_CHANNEL_VERSION; 578 598 chan->n_subbufs = n_subbufs; 579 599 chan->subbuf_size = subbuf_size; ··· 590 608 591 609 mutex_lock(&relay_channels_mutex); 592 610 for_each_online_cpu(i) { 593 - chan->buf[i] = relay_open_buf(chan, i); 594 - if (!chan->buf[i]) 611 + buf = relay_open_buf(chan, i); 612 + if (!buf) 595 613 goto free_bufs; 614 + *per_cpu_ptr(chan->buf, i) = buf; 596 615 } 597 616 list_add(&chan->list, &relay_channels); 598 617 mutex_unlock(&relay_channels_mutex); ··· 602 619 603 620 free_bufs: 604 621 for_each_possible_cpu(i) { 605 - if (chan->buf[i]) 606 - relay_close_buf(chan->buf[i]); 622 + if ((buf = *per_cpu_ptr(chan->buf, i))) 623 + relay_close_buf(buf); 607 624 } 608 625 609 626 kref_put(&chan->kref, relay_destroy_channel); ··· 649 666 unsigned int i, curr_cpu; 650 667 unsigned long flags; 651 668 struct dentry *dentry; 669 + struct rchan_buf *buf; 652 670 struct rchan_percpu_buf_dispatcher disp; 653 671 654 672 if (!chan || !base_filename) ··· 668 684 669 685 if (chan->is_global) { 670 686 err = -EINVAL; 671 - if (!WARN_ON_ONCE(!chan->buf[0])) { 672 - dentry = relay_create_buf_file(chan, chan->buf[0], 0); 687 + buf = *per_cpu_ptr(chan->buf, 0); 688 + if (!WARN_ON_ONCE(!buf)) { 689 + dentry = relay_create_buf_file(chan, buf, 0); 673 690 if (dentry && !WARN_ON_ONCE(!chan->is_global)) { 674 - relay_set_buf_dentry(chan->buf[0], dentry); 691 + relay_set_buf_dentry(buf, dentry); 675 692 err = 0; 676 693 } 677 694 } ··· 687 702 * on all currently online CPUs. 688 703 */ 689 704 for_each_online_cpu(i) { 690 - if (unlikely(!chan->buf[i])) { 705 + buf = *per_cpu_ptr(chan->buf, i); 706 + if (unlikely(!buf)) { 691 707 WARN_ONCE(1, KERN_ERR "CPU has no buffer!\n"); 692 708 err = -EINVAL; 693 709 break; 694 710 } 695 711 696 - dentry = relay_create_buf_file(chan, chan->buf[i], i); 712 + dentry = relay_create_buf_file(chan, buf, i); 697 713 if (unlikely(!dentry)) { 698 714 err = -EINVAL; 699 715 break; ··· 702 716 703 717 if (curr_cpu == i) { 704 718 local_irq_save(flags); 705 - relay_set_buf_dentry(chan->buf[i], dentry); 719 + relay_set_buf_dentry(buf, dentry); 706 720 local_irq_restore(flags); 707 721 } else { 708 - disp.buf = chan->buf[i]; 722 + disp.buf = buf; 709 723 disp.dentry = dentry; 710 724 smp_mb(); 711 725 /* relay_channels_mutex must be held, so wait. */ ··· 808 822 if (!chan) 809 823 return; 810 824 811 - if (cpu >= NR_CPUS || !chan->buf[cpu] || 812 - subbufs_consumed > chan->n_subbufs) 825 + buf = *per_cpu_ptr(chan->buf, cpu); 826 + if (cpu >= NR_CPUS || !buf || subbufs_consumed > chan->n_subbufs) 813 827 return; 814 828 815 - buf = chan->buf[cpu]; 816 829 if (subbufs_consumed > buf->subbufs_produced - buf->subbufs_consumed) 817 830 buf->subbufs_consumed = buf->subbufs_produced; 818 831 else ··· 827 842 */ 828 843 void relay_close(struct rchan *chan) 829 844 { 845 + struct rchan_buf *buf; 830 846 unsigned int i; 831 847 832 848 if (!chan) 833 849 return; 834 850 835 851 mutex_lock(&relay_channels_mutex); 836 - if (chan->is_global && chan->buf[0]) 837 - relay_close_buf(chan->buf[0]); 852 + if (chan->is_global && (buf = *per_cpu_ptr(chan->buf, 0))) 853 + relay_close_buf(buf); 838 854 else 839 855 for_each_possible_cpu(i) 840 - if (chan->buf[i]) 841 - relay_close_buf(chan->buf[i]); 856 + if ((buf = *per_cpu_ptr(chan->buf, i))) 857 + relay_close_buf(buf); 842 858 843 859 if (chan->last_toobig) 844 860 printk(KERN_WARNING "relay: one or more items not logged " ··· 860 874 */ 861 875 void relay_flush(struct rchan *chan) 862 876 { 877 + struct rchan_buf *buf; 863 878 unsigned int i; 864 879 865 880 if (!chan) 866 881 return; 867 882 868 - if (chan->is_global && chan->buf[0]) { 869 - relay_switch_subbuf(chan->buf[0], 0); 883 + if (chan->is_global && (buf = *per_cpu_ptr(chan->buf, 0))) { 884 + relay_switch_subbuf(buf, 0); 870 885 return; 871 886 } 872 887 873 888 mutex_lock(&relay_channels_mutex); 874 889 for_each_possible_cpu(i) 875 - if (chan->buf[i]) 876 - relay_switch_subbuf(chan->buf[i], 0); 890 + if ((buf = *per_cpu_ptr(chan->buf, i))) 891 + relay_switch_subbuf(buf, 0); 877 892 mutex_unlock(&relay_channels_mutex); 878 893 } 879 894 EXPORT_SYMBOL_GPL(relay_flush); ··· 1364 1377 .splice_read = relay_file_splice_read, 1365 1378 }; 1366 1379 EXPORT_SYMBOL_GPL(relay_file_operations); 1367 - 1368 - static __init int relay_init(void) 1369 - { 1370 - 1371 - hotcpu_notifier(relay_hotcpu_callback, 0); 1372 - return 0; 1373 - } 1374 - 1375 - early_initcall(relay_init);
+6 -21
kernel/softirq.c
··· 714 714 BUG(); 715 715 } 716 716 717 - static void takeover_tasklets(unsigned int cpu) 717 + static int takeover_tasklets(unsigned int cpu) 718 718 { 719 719 /* CPU is dead, so no lock needed. */ 720 720 local_irq_disable(); ··· 737 737 raise_softirq_irqoff(HI_SOFTIRQ); 738 738 739 739 local_irq_enable(); 740 + return 0; 740 741 } 742 + #else 743 + #define takeover_tasklets NULL 741 744 #endif /* CONFIG_HOTPLUG_CPU */ 742 - 743 - static int cpu_callback(struct notifier_block *nfb, unsigned long action, 744 - void *hcpu) 745 - { 746 - switch (action) { 747 - #ifdef CONFIG_HOTPLUG_CPU 748 - case CPU_DEAD: 749 - case CPU_DEAD_FROZEN: 750 - takeover_tasklets((unsigned long)hcpu); 751 - break; 752 - #endif /* CONFIG_HOTPLUG_CPU */ 753 - } 754 - return NOTIFY_OK; 755 - } 756 - 757 - static struct notifier_block cpu_nfb = { 758 - .notifier_call = cpu_callback 759 - }; 760 745 761 746 static struct smp_hotplug_thread softirq_threads = { 762 747 .store = &ksoftirqd, ··· 752 767 753 768 static __init int spawn_ksoftirqd(void) 754 769 { 755 - register_cpu_notifier(&cpu_nfb); 756 - 770 + cpuhp_setup_state_nocalls(CPUHP_SOFTIRQ_DEAD, "softirq:dead", NULL, 771 + takeover_tasklets); 757 772 BUG_ON(smpboot_register_percpu_thread(&softirq_threads)); 758 773 759 774 return 0;
+40 -6
lib/cpu-notifier-error-inject.c
··· 8 8 module_param(priority, int, 0); 9 9 MODULE_PARM_DESC(priority, "specify cpu notifier priority"); 10 10 11 + #define UP_PREPARE 0 12 + #define UP_PREPARE_FROZEN 0 13 + #define DOWN_PREPARE 0 14 + #define DOWN_PREPARE_FROZEN 0 15 + 11 16 static struct notifier_err_inject cpu_notifier_err_inject = { 12 17 .actions = { 13 - { NOTIFIER_ERR_INJECT_ACTION(CPU_UP_PREPARE) }, 14 - { NOTIFIER_ERR_INJECT_ACTION(CPU_UP_PREPARE_FROZEN) }, 15 - { NOTIFIER_ERR_INJECT_ACTION(CPU_DOWN_PREPARE) }, 16 - { NOTIFIER_ERR_INJECT_ACTION(CPU_DOWN_PREPARE_FROZEN) }, 18 + { NOTIFIER_ERR_INJECT_ACTION(UP_PREPARE) }, 19 + { NOTIFIER_ERR_INJECT_ACTION(UP_PREPARE_FROZEN) }, 20 + { NOTIFIER_ERR_INJECT_ACTION(DOWN_PREPARE) }, 21 + { NOTIFIER_ERR_INJECT_ACTION(DOWN_PREPARE_FROZEN) }, 17 22 {} 18 23 } 19 24 }; 25 + 26 + static int notf_err_handle(struct notifier_err_inject_action *action) 27 + { 28 + int ret; 29 + 30 + ret = action->error; 31 + if (ret) 32 + pr_info("Injecting error (%d) to %s\n", ret, action->name); 33 + return ret; 34 + } 35 + 36 + static int notf_err_inj_up_prepare(unsigned int cpu) 37 + { 38 + if (!cpuhp_tasks_frozen) 39 + return notf_err_handle(&cpu_notifier_err_inject.actions[0]); 40 + else 41 + return notf_err_handle(&cpu_notifier_err_inject.actions[1]); 42 + } 43 + 44 + static int notf_err_inj_dead(unsigned int cpu) 45 + { 46 + if (!cpuhp_tasks_frozen) 47 + return notf_err_handle(&cpu_notifier_err_inject.actions[2]); 48 + else 49 + return notf_err_handle(&cpu_notifier_err_inject.actions[3]); 50 + } 20 51 21 52 static struct dentry *dir; 22 53 ··· 60 29 if (IS_ERR(dir)) 61 30 return PTR_ERR(dir); 62 31 63 - err = register_hotcpu_notifier(&cpu_notifier_err_inject.nb); 32 + err = cpuhp_setup_state_nocalls(CPUHP_NOTF_ERR_INJ_PREPARE, 33 + "cpu-err-notif:prepare", 34 + notf_err_inj_up_prepare, 35 + notf_err_inj_dead); 64 36 if (err) 65 37 debugfs_remove_recursive(dir); 66 38 ··· 72 38 73 39 static void err_inject_exit(void) 74 40 { 75 - unregister_hotcpu_notifier(&cpu_notifier_err_inject.nb); 41 + cpuhp_remove_state_nocalls(CPUHP_NOTF_ERR_INJ_PREPARE); 76 42 debugfs_remove_recursive(dir); 77 43 } 78 44
+9 -17
lib/irq_poll.c
··· 184 184 } 185 185 EXPORT_SYMBOL(irq_poll_init); 186 186 187 - static int irq_poll_cpu_notify(struct notifier_block *self, 188 - unsigned long action, void *hcpu) 187 + static int irq_poll_cpu_dead(unsigned int cpu) 189 188 { 190 189 /* 191 190 * If a CPU goes away, splice its entries to the current CPU 192 191 * and trigger a run of the softirq 193 192 */ 194 - if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) { 195 - int cpu = (unsigned long) hcpu; 193 + local_irq_disable(); 194 + list_splice_init(&per_cpu(blk_cpu_iopoll, cpu), 195 + this_cpu_ptr(&blk_cpu_iopoll)); 196 + __raise_softirq_irqoff(IRQ_POLL_SOFTIRQ); 197 + local_irq_enable(); 196 198 197 - local_irq_disable(); 198 - list_splice_init(&per_cpu(blk_cpu_iopoll, cpu), 199 - this_cpu_ptr(&blk_cpu_iopoll)); 200 - __raise_softirq_irqoff(IRQ_POLL_SOFTIRQ); 201 - local_irq_enable(); 202 - } 203 - 204 - return NOTIFY_OK; 199 + return 0; 205 200 } 206 - 207 - static struct notifier_block irq_poll_cpu_notifier = { 208 - .notifier_call = irq_poll_cpu_notify, 209 - }; 210 201 211 202 static __init int irq_poll_setup(void) 212 203 { ··· 207 216 INIT_LIST_HEAD(&per_cpu(blk_cpu_iopoll, i)); 208 217 209 218 open_softirq(IRQ_POLL_SOFTIRQ, irq_poll_softirq); 210 - register_hotcpu_notifier(&irq_poll_cpu_notifier); 219 + cpuhp_setup_state_nocalls(CPUHP_IRQ_POLL_DEAD, "irq_poll:dead", NULL, 220 + irq_poll_cpu_dead); 211 221 return 0; 212 222 } 213 223 subsys_initcall(irq_poll_setup);
+7 -19
mm/page-writeback.c
··· 2080 2080 ratelimit_pages = 16; 2081 2081 } 2082 2082 2083 - static int 2084 - ratelimit_handler(struct notifier_block *self, unsigned long action, 2085 - void *hcpu) 2083 + static int page_writeback_cpu_online(unsigned int cpu) 2086 2084 { 2087 - 2088 - switch (action & ~CPU_TASKS_FROZEN) { 2089 - case CPU_ONLINE: 2090 - case CPU_DEAD: 2091 - writeback_set_ratelimit(); 2092 - return NOTIFY_OK; 2093 - default: 2094 - return NOTIFY_DONE; 2095 - } 2085 + writeback_set_ratelimit(); 2086 + return 0; 2096 2087 } 2097 - 2098 - static struct notifier_block ratelimit_nb = { 2099 - .notifier_call = ratelimit_handler, 2100 - .next = NULL, 2101 - }; 2102 2088 2103 2089 /* 2104 2090 * Called early on to tune the page writeback dirty limits. ··· 2108 2122 { 2109 2123 BUG_ON(wb_domain_init(&global_wb_domain, GFP_KERNEL)); 2110 2124 2111 - writeback_set_ratelimit(); 2112 - register_cpu_notifier(&ratelimit_nb); 2125 + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mm/writeback:online", 2126 + page_writeback_cpu_online, NULL); 2127 + cpuhp_setup_state(CPUHP_MM_WRITEBACK_DEAD, "mm/writeback:dead", NULL, 2128 + page_writeback_cpu_online); 2113 2129 } 2114 2130 2115 2131 /**
+52 -64
mm/slab.c
··· 886 886 return 0; 887 887 } 888 888 889 + #if (defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG)) || defined(CONFIG_SMP) 889 890 /* 890 891 * Allocates and initializes node for a node on each slab cache, used for 891 892 * either memory or cpu hotplug. If memory is being hot-added, the kmem_cache_node ··· 909 908 910 909 return 0; 911 910 } 911 + #endif 912 912 913 913 static int setup_kmem_cache_node(struct kmem_cache *cachep, 914 914 int node, gfp_t gfp, bool force_change) ··· 976 974 977 975 return ret; 978 976 } 977 + 978 + #ifdef CONFIG_SMP 979 979 980 980 static void cpuup_canceled(long cpu) 981 981 { ··· 1079 1075 return -ENOMEM; 1080 1076 } 1081 1077 1082 - static int cpuup_callback(struct notifier_block *nfb, 1083 - unsigned long action, void *hcpu) 1078 + int slab_prepare_cpu(unsigned int cpu) 1084 1079 { 1085 - long cpu = (long)hcpu; 1086 - int err = 0; 1080 + int err; 1087 1081 1088 - switch (action) { 1089 - case CPU_UP_PREPARE: 1090 - case CPU_UP_PREPARE_FROZEN: 1091 - mutex_lock(&slab_mutex); 1092 - err = cpuup_prepare(cpu); 1093 - mutex_unlock(&slab_mutex); 1094 - break; 1095 - case CPU_ONLINE: 1096 - case CPU_ONLINE_FROZEN: 1097 - start_cpu_timer(cpu); 1098 - break; 1099 - #ifdef CONFIG_HOTPLUG_CPU 1100 - case CPU_DOWN_PREPARE: 1101 - case CPU_DOWN_PREPARE_FROZEN: 1102 - /* 1103 - * Shutdown cache reaper. Note that the slab_mutex is 1104 - * held so that if cache_reap() is invoked it cannot do 1105 - * anything expensive but will only modify reap_work 1106 - * and reschedule the timer. 1107 - */ 1108 - cancel_delayed_work_sync(&per_cpu(slab_reap_work, cpu)); 1109 - /* Now the cache_reaper is guaranteed to be not running. */ 1110 - per_cpu(slab_reap_work, cpu).work.func = NULL; 1111 - break; 1112 - case CPU_DOWN_FAILED: 1113 - case CPU_DOWN_FAILED_FROZEN: 1114 - start_cpu_timer(cpu); 1115 - break; 1116 - case CPU_DEAD: 1117 - case CPU_DEAD_FROZEN: 1118 - /* 1119 - * Even if all the cpus of a node are down, we don't free the 1120 - * kmem_cache_node of any cache. This to avoid a race between 1121 - * cpu_down, and a kmalloc allocation from another cpu for 1122 - * memory from the node of the cpu going down. The node 1123 - * structure is usually allocated from kmem_cache_create() and 1124 - * gets destroyed at kmem_cache_destroy(). 1125 - */ 1126 - /* fall through */ 1127 - #endif 1128 - case CPU_UP_CANCELED: 1129 - case CPU_UP_CANCELED_FROZEN: 1130 - mutex_lock(&slab_mutex); 1131 - cpuup_canceled(cpu); 1132 - mutex_unlock(&slab_mutex); 1133 - break; 1134 - } 1135 - return notifier_from_errno(err); 1082 + mutex_lock(&slab_mutex); 1083 + err = cpuup_prepare(cpu); 1084 + mutex_unlock(&slab_mutex); 1085 + return err; 1136 1086 } 1137 1087 1138 - static struct notifier_block cpucache_notifier = { 1139 - &cpuup_callback, NULL, 0 1140 - }; 1088 + /* 1089 + * This is called for a failed online attempt and for a successful 1090 + * offline. 1091 + * 1092 + * Even if all the cpus of a node are down, we don't free the 1093 + * kmem_list3 of any cache. This to avoid a race between cpu_down, and 1094 + * a kmalloc allocation from another cpu for memory from the node of 1095 + * the cpu going down. The list3 structure is usually allocated from 1096 + * kmem_cache_create() and gets destroyed at kmem_cache_destroy(). 1097 + */ 1098 + int slab_dead_cpu(unsigned int cpu) 1099 + { 1100 + mutex_lock(&slab_mutex); 1101 + cpuup_canceled(cpu); 1102 + mutex_unlock(&slab_mutex); 1103 + return 0; 1104 + } 1105 + #endif 1106 + 1107 + static int slab_online_cpu(unsigned int cpu) 1108 + { 1109 + start_cpu_timer(cpu); 1110 + return 0; 1111 + } 1112 + 1113 + static int slab_offline_cpu(unsigned int cpu) 1114 + { 1115 + /* 1116 + * Shutdown cache reaper. Note that the slab_mutex is held so 1117 + * that if cache_reap() is invoked it cannot do anything 1118 + * expensive but will only modify reap_work and reschedule the 1119 + * timer. 1120 + */ 1121 + cancel_delayed_work_sync(&per_cpu(slab_reap_work, cpu)); 1122 + /* Now the cache_reaper is guaranteed to be not running. */ 1123 + per_cpu(slab_reap_work, cpu).work.func = NULL; 1124 + return 0; 1125 + } 1141 1126 1142 1127 #if defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG) 1143 1128 /* ··· 1329 1336 /* Done! */ 1330 1337 slab_state = FULL; 1331 1338 1332 - /* 1333 - * Register a cpu startup notifier callback that initializes 1334 - * cpu_cache_get for all new cpus 1335 - */ 1336 - register_cpu_notifier(&cpucache_notifier); 1337 - 1338 1339 #ifdef CONFIG_NUMA 1339 1340 /* 1340 1341 * Register a memory hotplug callback that initializes and frees ··· 1345 1358 1346 1359 static int __init cpucache_init(void) 1347 1360 { 1348 - int cpu; 1361 + int ret; 1349 1362 1350 1363 /* 1351 1364 * Register the timers that return unneeded pages to the page allocator 1352 1365 */ 1353 - for_each_online_cpu(cpu) 1354 - start_cpu_timer(cpu); 1366 + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "SLAB online", 1367 + slab_online_cpu, slab_offline_cpu); 1368 + WARN_ON(ret < 0); 1355 1369 1356 1370 /* Done! */ 1357 1371 slab_state = FULL;
+21 -44
mm/slub.c
··· 194 194 #define __OBJECT_POISON 0x80000000UL /* Poison object */ 195 195 #define __CMPXCHG_DOUBLE 0x40000000UL /* Use cmpxchg_double */ 196 196 197 - #ifdef CONFIG_SMP 198 - static struct notifier_block slab_notifier; 199 - #endif 200 - 201 197 /* 202 198 * Tracking user of a slab. 203 199 */ ··· 2301 2305 } 2302 2306 2303 2307 /* 2308 + * Use the cpu notifier to insure that the cpu slabs are flushed when 2309 + * necessary. 2310 + */ 2311 + static int slub_cpu_dead(unsigned int cpu) 2312 + { 2313 + struct kmem_cache *s; 2314 + unsigned long flags; 2315 + 2316 + mutex_lock(&slab_mutex); 2317 + list_for_each_entry(s, &slab_caches, list) { 2318 + local_irq_save(flags); 2319 + __flush_cpu_slab(s, cpu); 2320 + local_irq_restore(flags); 2321 + } 2322 + mutex_unlock(&slab_mutex); 2323 + return 0; 2324 + } 2325 + 2326 + /* 2304 2327 * Check if the objects in a per cpu structure fit numa 2305 2328 * locality expectations. 2306 2329 */ ··· 4159 4144 /* Setup random freelists for each cache */ 4160 4145 init_freelist_randomization(); 4161 4146 4162 - #ifdef CONFIG_SMP 4163 - register_cpu_notifier(&slab_notifier); 4164 - #endif 4147 + cpuhp_setup_state_nocalls(CPUHP_SLUB_DEAD, "slub:dead", NULL, 4148 + slub_cpu_dead); 4165 4149 4166 4150 pr_info("SLUB: HWalign=%d, Order=%d-%d, MinObjects=%d, CPUs=%d, Nodes=%d\n", 4167 4151 cache_line_size(), ··· 4223 4209 4224 4210 return err; 4225 4211 } 4226 - 4227 - #ifdef CONFIG_SMP 4228 - /* 4229 - * Use the cpu notifier to insure that the cpu slabs are flushed when 4230 - * necessary. 4231 - */ 4232 - static int slab_cpuup_callback(struct notifier_block *nfb, 4233 - unsigned long action, void *hcpu) 4234 - { 4235 - long cpu = (long)hcpu; 4236 - struct kmem_cache *s; 4237 - unsigned long flags; 4238 - 4239 - switch (action) { 4240 - case CPU_UP_CANCELED: 4241 - case CPU_UP_CANCELED_FROZEN: 4242 - case CPU_DEAD: 4243 - case CPU_DEAD_FROZEN: 4244 - mutex_lock(&slab_mutex); 4245 - list_for_each_entry(s, &slab_caches, list) { 4246 - local_irq_save(flags); 4247 - __flush_cpu_slab(s, cpu); 4248 - local_irq_restore(flags); 4249 - } 4250 - mutex_unlock(&slab_mutex); 4251 - break; 4252 - default: 4253 - break; 4254 - } 4255 - return NOTIFY_OK; 4256 - } 4257 - 4258 - static struct notifier_block slab_notifier = { 4259 - .notifier_call = slab_cpuup_callback 4260 - }; 4261 - 4262 - #endif 4263 4212 4264 4213 void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller) 4265 4214 {
-13
tools/testing/radix-tree/linux/cpu.h
··· 7 7 #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */ 8 8 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */ 9 9 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */ 10 - #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task, 11 - * not handling interrupts, soon dead. 12 - * Called on the dying cpu, interrupts 13 - * are already disabled. Must not 14 - * sleep, must not fail */ 15 10 #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug 16 11 * lock is dropped */ 17 - #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running. 18 - * Called on the new cpu, just before 19 - * enabling interrupts. Must not sleep, 20 - * must not fail */ 21 - #define CPU_DYING_IDLE 0x000B /* CPU (unsigned)v dying, reached 22 - * idle loop. */ 23 12 #define CPU_BROKEN 0x000C /* CPU (unsigned)v did not die properly, 24 13 * perhaps due to preemption. */ 25 14 #define CPU_TASKS_FROZEN 0x0010 ··· 19 30 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN) 20 31 #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN) 21 32 #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN) 22 - #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN) 23 - #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)