Blame view
drivers/xen/cpu_hotplug.c
2.29 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
283c0972d xen: Convert prin... |
2 |
#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt |
d68d82afd xen: implement CP... |
3 |
#include <linux/notifier.h> |
1ccbf5344 xen: move Xen-tes... |
4 |
#include <xen/xen.h> |
d68d82afd xen: implement CP... |
5 |
#include <xen/xenbus.h> |
bb8985586 x86, um: ... and ... |
6 |
#include <asm/xen/hypervisor.h> |
d68d82afd xen: implement CP... |
7 8 9 10 11 |
#include <asm/cpu.h> static void enable_hotplug_cpu(int cpu) { if (!cpu_present(cpu)) |
a314e3eb8 xen/arm: Enable c... |
12 |
xen_arch_register_cpu(cpu); |
d68d82afd xen: implement CP... |
13 |
|
d680eb8bc cpumask: make Xen... |
14 |
set_cpu_present(cpu, true); |
d68d82afd xen: implement CP... |
15 16 17 18 |
} static void disable_hotplug_cpu(int cpu) { |
3366cdb6d xen: avoid crash ... |
19 20 21 22 |
if (!cpu_is_hotpluggable(cpu)) return; lock_device_hotplug(); if (cpu_online(cpu)) |
1c7a62137 xen, cpu_hotplug:... |
23 |
device_offline(get_cpu_device(cpu)); |
3366cdb6d xen: avoid crash ... |
24 |
if (!cpu_online(cpu) && cpu_present(cpu)) { |
a314e3eb8 xen/arm: Enable c... |
25 |
xen_arch_unregister_cpu(cpu); |
3366cdb6d xen: avoid crash ... |
26 27 28 |
set_cpu_present(cpu, false); } unlock_device_hotplug(); |
d68d82afd xen: implement CP... |
29 |
} |
d745562cc xen: honour VCPU ... |
30 |
static int vcpu_online(unsigned int cpu) |
d68d82afd xen: implement CP... |
31 32 |
{ int err; |
e5c702d3b Xen: properly bou... |
33 |
char dir[16], state[16]; |
d68d82afd xen: implement CP... |
34 |
|
d68d82afd xen: implement CP... |
35 |
sprintf(dir, "cpu/%u", cpu); |
e5c702d3b Xen: properly bou... |
36 |
err = xenbus_scanf(XBT_NIL, dir, "availability", "%15s", state); |
d68d82afd xen: implement CP... |
37 |
if (err != 1) { |
5b02aa1e6 xen/bootup: Durin... |
38 |
if (!xen_initial_domain()) |
283c0972d xen: Convert prin... |
39 40 |
pr_err("Unable to read cpu state "); |
d745562cc xen: honour VCPU ... |
41 |
return err; |
d68d82afd xen: implement CP... |
42 |
} |
d745562cc xen: honour VCPU ... |
43 44 45 46 |
if (strcmp(state, "online") == 0) return 1; else if (strcmp(state, "offline") == 0) return 0; |
283c0972d xen: Convert prin... |
47 48 |
pr_err("unknown state(%s) on CPU%d ", state, cpu); |
d745562cc xen: honour VCPU ... |
49 50 51 52 |
return -EINVAL; } static void vcpu_hotplug(unsigned int cpu) { |
201676095 xen, cpu_hotplug:... |
53 |
if (cpu >= nr_cpu_ids || !cpu_possible(cpu)) |
d745562cc xen: honour VCPU ... |
54 55 56 57 |
return; switch (vcpu_online(cpu)) { case 1: |
d68d82afd xen: implement CP... |
58 |
enable_hotplug_cpu(cpu); |
d745562cc xen: honour VCPU ... |
59 60 |
break; case 0: |
d68d82afd xen: implement CP... |
61 |
disable_hotplug_cpu(cpu); |
d745562cc xen: honour VCPU ... |
62 63 64 |
break; default: break; |
d68d82afd xen: implement CP... |
65 66 67 68 |
} } static void handle_vcpu_hotplug_event(struct xenbus_watch *watch, |
5584ea250 xen: modify xenst... |
69 |
const char *path, const char *token) |
d68d82afd xen: implement CP... |
70 71 72 |
{ unsigned int cpu; char *cpustr; |
d68d82afd xen: implement CP... |
73 |
|
5584ea250 xen: modify xenst... |
74 |
cpustr = strstr(path, "cpu/"); |
d68d82afd xen: implement CP... |
75 76 77 78 79 80 81 82 83 |
if (cpustr != NULL) { sscanf(cpustr, "cpu/%u", &cpu); vcpu_hotplug(cpu); } } static int setup_cpu_watcher(struct notifier_block *notifier, unsigned long event, void *data) { |
d745562cc xen: honour VCPU ... |
84 |
int cpu; |
d68d82afd xen: implement CP... |
85 86 87 88 89 |
static struct xenbus_watch cpu_watch = { .node = "cpu", .callback = handle_vcpu_hotplug_event}; (void)register_xenbus_watch(&cpu_watch); |
d745562cc xen: honour VCPU ... |
90 |
for_each_possible_cpu(cpu) { |
c54b071c1 xen/cpuhotplug: F... |
91 92 |
if (vcpu_online(cpu) == 0) disable_hotplug_cpu(cpu); |
d745562cc xen: honour VCPU ... |
93 |
} |
d68d82afd xen: implement CP... |
94 95 96 97 98 99 100 |
return NOTIFY_DONE; } static int __init setup_vcpu_hotplug_event(void) { static struct notifier_block xsn_cpu = { .notifier_call = setup_cpu_watcher }; |
a314e3eb8 xen/arm: Enable c... |
101 |
#ifdef CONFIG_X86 |
2a7197f02 xen/pvh: Enable C... |
102 |
if (!xen_pv_domain() && !xen_pvh_domain()) |
a314e3eb8 xen/arm: Enable c... |
103 104 105 |
#else if (!xen_domain()) #endif |
d68d82afd xen: implement CP... |
106 107 108 109 110 111 |
return -ENODEV; register_xenstore_notifier(&xsn_cpu); return 0; } |
c54b071c1 xen/cpuhotplug: F... |
112 |
late_initcall(setup_vcpu_hotplug_event); |
d68d82afd xen: implement CP... |
113 |