Skip to content

Commit 74b8423

Browse files
committed
Merge branch 'x86-bsp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 BSP hotplug changes from Ingo Molnar: "This tree enables CPU#0 (the boot processor) to be onlined/offlined on x86, just like any other CPU. Enabled on Intel CPUs for now. Allowing this required the identification and fixing of latent CPU#0 assumptions (such as CPU#0 initializations, etc.) in the x86 architecture code, plus the identification of barriers to BSP-offlining, such as active PIC interrupts which can only be serviced on the BSP. It's behind a default-off option, and there's a debug option that allows the automatic testing of this feature. The motivation of this feature is to allow and prepare for true CPU-hotplug hardware support: recent changes to MCE support enable us to detect a deteriorating but not yet hard-failing L1/L2 cache on a CPU that could be soft-unplugged - or a failing L3 cache on a multi-socket system. Note that true hardware hot-plug is not yet fully enabled by this, because that requires a special platform wakeup sequence to be sent to the freshly powered up CPU#0. Future patches for this are planned, once such a platform exists. Chicken and egg" * 'x86-bsp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86, topology: Debug CPU0 hotplug x86/i387.c: Initialize thread xstate only on CPU0 only once x86, hotplug: Handle retrigger irq by the first available CPU x86, hotplug: The first online processor saves the MTRR state x86, hotplug: During CPU0 online, enable x2apic, set_numa_node. x86, hotplug: Wake up CPU0 via NMI instead of INIT, SIPI, SIPI x86-32, hotplug: Add start_cpu0() entry point to head_32.S x86-64, hotplug: Add start_cpu0() entry point to head_64.S kernel/cpu.c: Add comment for priority in cpu_hotplug_pm_callback x86, hotplug, suspend: Online CPU0 for suspend or hibernate x86, hotplug: Support functions for CPU0 online/offline x86, topology: Don't offline CPU0 if any PIC irq can not be migrated out of it x86, Kconfig: Add config switch for CPU0 hotplug doc: Add x86 CPU0 online/offline feature
2 parents 5074474 + a71c8bc commit 74b8423

15 files changed

Lines changed: 436 additions & 41 deletions

File tree

‎Documentation/cpu-hotplug.txt‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,30 @@ by making it not-removable.
207207

208208
In such cases you will also notice that the online file is missing under cpu0.
209209

210+
Q: Is CPU0 removable on X86?
211+
A: Yes. If kernel is compiled with CONFIG_BOOTPARAM_HOTPLUG_CPU0=y, CPU0 is
212+
removable by default. Otherwise, CPU0 is also removable by kernel option
213+
cpu0_hotplug.
214+
215+
But some features depend on CPU0. Two known dependencies are:
216+
217+
1. Resume from hibernate/suspend depends on CPU0. Hibernate/suspend will fail if
218+
CPU0 is offline and you need to online CPU0 before hibernate/suspend can
219+
continue.
220+
2. PIC interrupts also depend on CPU0. CPU0 can't be removed if a PIC interrupt
221+
is detected.
222+
223+
It's said poweroff/reboot may depend on CPU0 on some machines although I haven't
224+
seen any poweroff/reboot failure so far after CPU0 is offline on a few tested
225+
machines.
226+
227+
Please let me know if you know or see any other dependencies of CPU0.
228+
229+
If the dependencies are under your control, you can turn on CPU0 hotplug feature
230+
either by CONFIG_BOOTPARAM_HOTPLUG_CPU0 or by kernel parameter cpu0_hotplug.
231+
232+
--Fenghua Yu <fenghua.yu@intel.com>
233+
210234
Q: How do i find out if a particular CPU is not removable?
211235
A: Depending on the implementation, some architectures may show this by the
212236
absence of the "online" file. This is done if it can be determined ahead of

‎Documentation/kernel-parameters.txt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,20 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
19841984

19851985
nox2apic [X86-64,APIC] Do not enable x2APIC mode.
19861986

1987+
cpu0_hotplug [X86] Turn on CPU0 hotplug feature when
1988+
CONFIG_BOOTPARAM_HOTPLUG_CPU0 is off.
1989+
Some features depend on CPU0. Known dependencies are:
1990+
1. Resume from suspend/hibernate depends on CPU0.
1991+
Suspend/hibernate will fail if CPU0 is offline and you
1992+
need to online CPU0 before suspend/hibernate.
1993+
2. PIC interrupts also depend on CPU0. CPU0 can't be
1994+
removed if a PIC interrupt is detected.
1995+
It's said poweroff/reboot may depend on CPU0 on some
1996+
machines although I haven't seen such issues so far
1997+
after CPU0 is offline on a few tested machines.
1998+
If the dependencies are under your control, you can
1999+
turn on cpu0_hotplug.
2000+
19872001
nptcg= [IA-64] Override max number of concurrent global TLB
19882002
purges which is reported from either PAL_VM_SUMMARY or
19892003
SAL PALO.

‎arch/x86/Kconfig‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,50 @@ config HOTPLUG_CPU
16981698
automatically on SMP systems. )
16991699
Say N if you want to disable CPU hotplug.
17001700

1701+
config BOOTPARAM_HOTPLUG_CPU0
1702+
bool "Set default setting of cpu0_hotpluggable"
1703+
default n
1704+
depends on HOTPLUG_CPU && EXPERIMENTAL
1705+
---help---
1706+
Set whether default state of cpu0_hotpluggable is on or off.
1707+
1708+
Say Y here to enable CPU0 hotplug by default. If this switch
1709+
is turned on, there is no need to give cpu0_hotplug kernel
1710+
parameter and the CPU0 hotplug feature is enabled by default.
1711+
1712+
Please note: there are two known CPU0 dependencies if you want
1713+
to enable the CPU0 hotplug feature either by this switch or by
1714+
cpu0_hotplug kernel parameter.
1715+
1716+
First, resume from hibernate or suspend always starts from CPU0.
1717+
So hibernate and suspend are prevented if CPU0 is offline.
1718+
1719+
Second dependency is PIC interrupts always go to CPU0. CPU0 can not
1720+
offline if any interrupt can not migrate out of CPU0. There may
1721+
be other CPU0 dependencies.
1722+
1723+
Please make sure the dependencies are under your control before
1724+
you enable this feature.
1725+
1726+
Say N if you don't want to enable CPU0 hotplug feature by default.
1727+
You still can enable the CPU0 hotplug feature at boot by kernel
1728+
parameter cpu0_hotplug.
1729+
1730+
config DEBUG_HOTPLUG_CPU0
1731+
def_bool n
1732+
prompt "Debug CPU0 hotplug"
1733+
depends on HOTPLUG_CPU && EXPERIMENTAL
1734+
---help---
1735+
Enabling this option offlines CPU0 (if CPU0 can be offlined) as
1736+
soon as possible and boots up userspace with CPU0 offlined. User
1737+
can online CPU0 back after boot time.
1738+
1739+
To debug CPU0 hotplug, you need to enable CPU0 offline/online
1740+
feature by either turning on CONFIG_BOOTPARAM_HOTPLUG_CPU0 during
1741+
compilation or giving cpu0_hotplug kernel parameter at boot.
1742+
1743+
If unsure, say N.
1744+
17011745
config COMPAT_VDSO
17021746
def_bool y
17031747
prompt "Compat VDSO support"

‎arch/x86/include/asm/cpu.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ struct x86_cpu {
2828
#ifdef CONFIG_HOTPLUG_CPU
2929
extern int arch_register_cpu(int num);
3030
extern void arch_unregister_cpu(int);
31+
extern void __cpuinit start_cpu0(void);
32+
#ifdef CONFIG_DEBUG_HOTPLUG_CPU0
33+
extern int _debug_hotplug_cpu(int cpu, int action);
34+
#endif
3135
#endif
3236

3337
DECLARE_PER_CPU(int, cpu_state);

‎arch/x86/include/asm/smp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ void native_send_call_func_ipi(const struct cpumask *mask);
166166
void native_send_call_func_single_ipi(int cpu);
167167
void x86_idle_thread_init(unsigned int cpu, struct task_struct *idle);
168168

169+
void smp_store_boot_cpu_info(void);
169170
void smp_store_cpu_info(int id);
170171
#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
171172

‎arch/x86/kernel/apic/io_apic.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,9 +2199,11 @@ static int ioapic_retrigger_irq(struct irq_data *data)
21992199
{
22002200
struct irq_cfg *cfg = data->chip_data;
22012201
unsigned long flags;
2202+
int cpu;
22022203

22032204
raw_spin_lock_irqsave(&vector_lock, flags);
2204-
apic->send_IPI_mask(cpumask_of(cpumask_first(cfg->domain)), cfg->vector);
2205+
cpu = cpumask_first_and(cfg->domain, cpu_online_mask);
2206+
apic->send_IPI_mask(cpumask_of(cpu), cfg->vector);
22052207
raw_spin_unlock_irqrestore(&vector_lock, flags);
22062208

22072209
return 1;

‎arch/x86/kernel/cpu/common.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ void __cpuinit cpu_init(void)
12371237
oist = &per_cpu(orig_ist, cpu);
12381238

12391239
#ifdef CONFIG_NUMA
1240-
if (cpu != 0 && this_cpu_read(numa_node) == 0 &&
1240+
if (this_cpu_read(numa_node) == 0 &&
12411241
early_cpu_to_node(cpu) != NUMA_NO_NODE)
12421242
set_numa_node(early_cpu_to_node(cpu));
12431243
#endif
@@ -1269,8 +1269,7 @@ void __cpuinit cpu_init(void)
12691269
barrier();
12701270

12711271
x86_configure_nx();
1272-
if (cpu != 0)
1273-
enable_x2apic();
1272+
enable_x2apic();
12741273

12751274
/*
12761275
* set up and load the per-CPU TSS

‎arch/x86/kernel/cpu/mtrr/main.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,16 @@ void mtrr_ap_init(void)
695695
}
696696

697697
/**
698-
* Save current fixed-range MTRR state of the BSP
698+
* Save current fixed-range MTRR state of the first cpu in cpu_online_mask.
699699
*/
700700
void mtrr_save_state(void)
701701
{
702-
smp_call_function_single(0, mtrr_save_fixed_ranges, NULL, 1);
702+
int first_cpu;
703+
704+
get_online_cpus();
705+
first_cpu = cpumask_first(cpu_online_mask);
706+
smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
707+
put_online_cpus();
703708
}
704709

705710
void set_mtrr_aps_delayed_init(void)

‎arch/x86/kernel/head_32.S‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,19 @@ num_subarch_entries = (. - subarch_entries) / 4
266266
jmp default_entry
267267
#endif /* CONFIG_PARAVIRT */
268268

269+
#ifdef CONFIG_HOTPLUG_CPU
270+
/*
271+
* Boot CPU0 entry point. It's called from play_dead(). Everything has been set
272+
* up already except stack. We just set up stack here. Then call
273+
* start_secondary().
274+
*/
275+
ENTRY(start_cpu0)
276+
movl stack_start, %ecx
277+
movl %ecx, %esp
278+
jmp *(initial_code)
279+
ENDPROC(start_cpu0)
280+
#endif
281+
269282
/*
270283
* Non-boot CPU entry point; entered from trampoline.S
271284
* We can't lgdt here, because lgdt itself uses a data segment, but

‎arch/x86/kernel/head_64.S‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,22 @@ ENTRY(secondary_startup_64)
252252
pushq %rax # target address in negative space
253253
lretq
254254

255+
#ifdef CONFIG_HOTPLUG_CPU
256+
/*
257+
* Boot CPU0 entry point. It's called from play_dead(). Everything has been set
258+
* up already except stack. We just set up stack here. Then call
259+
* start_secondary().
260+
*/
261+
ENTRY(start_cpu0)
262+
movq stack_start(%rip),%rsp
263+
movq initial_code(%rip),%rax
264+
pushq $0 # fake return address to stop unwinder
265+
pushq $__KERNEL_CS # set correct cs
266+
pushq %rax # target address in negative space
267+
lretq
268+
ENDPROC(start_cpu0)
269+
#endif
270+
255271
/* SMP bootup changes these two */
256272
__REFDATA
257273
.align 8

0 commit comments

Comments
 (0)