Skip to content

Commit 93ef142

Browse files
Qais YousefKAGA-KOKO
Qais Yousef
authored andcommitted
cpu/hotplug: Add new {add,remove}_cpu() functions
The new functions use device_{online,offline}() which are userspace safe. This is in preparation to move cpu_{up, down} kernel users to use a safer interface that is not racy with userspace. Suggested-by: "Paul E. McKenney" <[email protected]> Signed-off-by: Qais Yousef <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Paul E. McKenney <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent fd3eafd commit 93ef142

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/linux/cpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ extern ssize_t arch_cpu_release(const char *, size_t);
8989
#ifdef CONFIG_SMP
9090
extern bool cpuhp_tasks_frozen;
9191
int cpu_up(unsigned int cpu);
92+
int add_cpu(unsigned int cpu);
9293
void notify_cpu_starting(unsigned int cpu);
9394
extern void cpu_maps_update_begin(void);
9495
extern void cpu_maps_update_done(void);
@@ -118,6 +119,7 @@ extern void cpu_hotplug_disable(void);
118119
extern void cpu_hotplug_enable(void);
119120
void clear_tasks_mm_cpumask(int cpu);
120121
int cpu_down(unsigned int cpu);
122+
int remove_cpu(unsigned int cpu);
121123

122124
#else /* CONFIG_HOTPLUG_CPU */
123125

kernel/cpu.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,18 @@ int cpu_down(unsigned int cpu)
10571057
}
10581058
EXPORT_SYMBOL(cpu_down);
10591059

1060+
int remove_cpu(unsigned int cpu)
1061+
{
1062+
int ret;
1063+
1064+
lock_device_hotplug();
1065+
ret = device_offline(get_cpu_device(cpu));
1066+
unlock_device_hotplug();
1067+
1068+
return ret;
1069+
}
1070+
EXPORT_SYMBOL_GPL(remove_cpu);
1071+
10601072
#else
10611073
#define takedown_cpu NULL
10621074
#endif /*CONFIG_HOTPLUG_CPU*/
@@ -1209,6 +1221,18 @@ int cpu_up(unsigned int cpu)
12091221
}
12101222
EXPORT_SYMBOL_GPL(cpu_up);
12111223

1224+
int add_cpu(unsigned int cpu)
1225+
{
1226+
int ret;
1227+
1228+
lock_device_hotplug();
1229+
ret = device_online(get_cpu_device(cpu));
1230+
unlock_device_hotplug();
1231+
1232+
return ret;
1233+
}
1234+
EXPORT_SYMBOL_GPL(add_cpu);
1235+
12121236
#ifdef CONFIG_PM_SLEEP_SMP
12131237
static cpumask_var_t frozen_cpus;
12141238

0 commit comments

Comments
 (0)