Juergen Gross | 901d209 | 2018-08-28 09:40:15 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | |
Boris Ostrovsky | b3cf852 | 2017-12-12 15:08:21 -0500 | [diff] [blame] | 3 | #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG |
Mike Rapoport | 57c8a66 | 2018-10-30 15:09:49 -0700 | [diff] [blame] | 4 | #include <linux/memblock.h> |
Boris Ostrovsky | b3cf852 | 2017-12-12 15:08:21 -0500 | [diff] [blame] | 5 | #endif |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 6 | #include <linux/cpu.h> |
Vitaly Kuznetsov | 0b34a16 | 2015-09-25 11:59:52 +0200 | [diff] [blame] | 7 | #include <linux/kexec.h> |
Nicolai Stange | 447ae31 | 2018-07-29 12:15:33 +0200 | [diff] [blame] | 8 | #include <linux/slab.h> |
Andy Shevchenko | f39650d | 2021-06-30 18:54:59 -0700 | [diff] [blame] | 9 | #include <linux/panic_notifier.h> |
Vitaly Kuznetsov | 0b34a16 | 2015-09-25 11:59:52 +0200 | [diff] [blame] | 10 | |
Christoph Hellwig | 3cfa210 | 2018-09-25 13:30:09 -0700 | [diff] [blame] | 11 | #include <xen/xen.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 12 | #include <xen/features.h> |
| 13 | #include <xen/page.h> |
| 14 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 15 | #include <asm/xen/hypercall.h> |
| 16 | #include <asm/xen/hypervisor.h> |
Stefano Stabellini | a314e3e | 2015-10-22 16:20:46 +0000 | [diff] [blame] | 17 | #include <asm/cpu.h> |
Ingo Molnar | 687d77a | 2017-03-01 08:49:47 +0100 | [diff] [blame] | 18 | #include <asm/e820/api.h> |
Konrad Rzeszutek Wilk | 73c154c | 2012-02-13 22:26:32 -0500 | [diff] [blame] | 19 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 20 | #include "xen-ops.h" |
Ben Guthro | f447d56 | 2012-04-21 00:11:04 +0800 | [diff] [blame] | 21 | #include "smp.h" |
Boris Ostrovsky | 65d0cf0 | 2015-08-10 16:34:34 -0400 | [diff] [blame] | 22 | #include "pmu.h" |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 23 | |
| 24 | EXPORT_SYMBOL_GPL(hypercall_page); |
| 25 | |
Konrad Rzeszutek Wilk | a520996 | 2013-05-05 08:51:47 -0400 | [diff] [blame] | 26 | /* |
| 27 | * Pointer to the xen_vcpu_info structure or |
| 28 | * &HYPERVISOR_shared_info->vcpu_info[cpu]. See xen_hvm_init_shared_info |
| 29 | * and xen_vcpu_setup for details. By default it points to share_info->vcpu_info |
| 30 | * but if the hypervisor supports VCPUOP_register_vcpu_info then it can point |
| 31 | * to xen_vcpu_info. The pointer is used in __xen_evtchn_do_upcall to |
| 32 | * acknowledge pending events. |
| 33 | * Also more subtly it is used by the patched version of irq enable/disable |
| 34 | * e.g. xen_irq_enable_direct and xen_iret in PV mode. |
| 35 | * |
| 36 | * The desire to be able to do those mask/unmask operations as a single |
| 37 | * instruction by using the per-cpu offset held in %gs is the real reason |
| 38 | * vcpu info is in a per-cpu pointer and the original reason for this |
| 39 | * hypercall. |
| 40 | * |
| 41 | */ |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 42 | DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu); |
Konrad Rzeszutek Wilk | a520996 | 2013-05-05 08:51:47 -0400 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Per CPU pages used if hypervisor supports VCPUOP_register_vcpu_info |
| 46 | * hypercall. This can be used both in PV and PVHVM mode. The structure |
| 47 | * overrides the default per_cpu(xen_vcpu, cpu) value. |
| 48 | */ |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 49 | DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info); |
Jeremy Fitzhardinge | 9f79991 | 2007-10-16 11:51:30 -0700 | [diff] [blame] | 50 | |
Vitaly Kuznetsov | 88e957d | 2016-06-30 17:56:37 +0200 | [diff] [blame] | 51 | /* Linux <-> Xen vCPU id mapping */ |
Vitaly Kuznetsov | 55467de | 2016-07-29 11:06:48 +0200 | [diff] [blame] | 52 | DEFINE_PER_CPU(uint32_t, xen_vcpu_id); |
Vitaly Kuznetsov | 88e957d | 2016-06-30 17:56:37 +0200 | [diff] [blame] | 53 | EXPORT_PER_CPU_SYMBOL(xen_vcpu_id); |
| 54 | |
Jeremy Fitzhardinge | 6e83358 | 2008-08-19 13:16:17 -0700 | [diff] [blame] | 55 | enum xen_domain_type xen_domain_type = XEN_NATIVE; |
| 56 | EXPORT_SYMBOL_GPL(xen_domain_type); |
| 57 | |
Ian Campbell | 7e77506 | 2010-09-30 12:37:26 +0100 | [diff] [blame] | 58 | unsigned long *machine_to_phys_mapping = (void *)MACH2PHYS_VIRT_START; |
| 59 | EXPORT_SYMBOL(machine_to_phys_mapping); |
Jan Beulich | ccbcdf7 | 2011-08-16 15:07:41 +0100 | [diff] [blame] | 60 | unsigned long machine_to_phys_nr; |
| 61 | EXPORT_SYMBOL(machine_to_phys_nr); |
Ian Campbell | 7e77506 | 2010-09-30 12:37:26 +0100 | [diff] [blame] | 62 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 63 | struct start_info *xen_start_info; |
| 64 | EXPORT_SYMBOL_GPL(xen_start_info); |
| 65 | |
Jeremy Fitzhardinge | a0d695c | 2008-05-26 23:31:21 +0100 | [diff] [blame] | 66 | struct shared_info xen_dummy_shared_info; |
Jeremy Fitzhardinge | 60223a3 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 67 | |
Boris Ostrovsky | 3dbd820 | 2017-05-02 13:23:06 -0400 | [diff] [blame] | 68 | __read_mostly int xen_have_vector_callback; |
| 69 | EXPORT_SYMBOL_GPL(xen_have_vector_callback); |
| 70 | |
Jeremy Fitzhardinge | 60223a3 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 71 | /* |
Roger Pau Monne | 1fe8388 | 2018-06-08 10:40:38 +0200 | [diff] [blame] | 72 | * NB: needs to live in .data because it's used by xen_prepare_pvh which runs |
| 73 | * before clearing the bss. |
| 74 | */ |
Joe Perches | 33def84 | 2020-10-21 19:36:07 -0700 | [diff] [blame] | 75 | uint32_t xen_start_flags __section(".data") = 0; |
Roger Pau Monne | 1fe8388 | 2018-06-08 10:40:38 +0200 | [diff] [blame] | 76 | EXPORT_SYMBOL(xen_start_flags); |
| 77 | |
| 78 | /* |
Jeremy Fitzhardinge | 60223a3 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 79 | * Point at some empty memory to start with. We map the real shared_info |
| 80 | * page as soon as fixmap is up and running. |
| 81 | */ |
Olaf Hering | 4648da7 | 2012-07-17 11:57:41 +0200 | [diff] [blame] | 82 | struct shared_info *HYPERVISOR_shared_info = &xen_dummy_shared_info; |
Jeremy Fitzhardinge | 60223a3 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Flag to determine whether vcpu info placement is available on all |
| 86 | * VCPUs. We assume it is to start with, and then set it to zero on |
| 87 | * the first failure. This is because it can succeed on some VCPUs |
| 88 | * and not others, since it can involve hypervisor memory allocation, |
| 89 | * or because the guest failed to guarantee all the appropriate |
| 90 | * constraints on all VCPUs (ie buffer can't cross a page boundary). |
| 91 | * |
| 92 | * Note that any particular CPU may be using a placed vcpu structure, |
| 93 | * but we can only optimise if the all are. |
| 94 | * |
| 95 | * 0: not available, 1: available |
| 96 | */ |
Vitaly Kuznetsov | 52519f2 | 2017-03-14 18:35:37 +0100 | [diff] [blame] | 97 | int xen_have_vcpu_info_placement = 1; |
Jeremy Fitzhardinge | 60223a3 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 98 | |
Vitaly Kuznetsov | e1dab14 | 2017-03-14 18:35:41 +0100 | [diff] [blame] | 99 | static int xen_cpu_up_online(unsigned int cpu) |
| 100 | { |
| 101 | xen_init_lock_cpu(cpu); |
| 102 | return 0; |
| 103 | } |
David Vrabel | 1c32cdc | 2012-07-09 11:39:08 +0100 | [diff] [blame] | 104 | |
Vitaly Kuznetsov | e1dab14 | 2017-03-14 18:35:41 +0100 | [diff] [blame] | 105 | int xen_cpuhp_setup(int (*cpu_up_prepare_cb)(unsigned int), |
| 106 | int (*cpu_dead_cb)(unsigned int)) |
| 107 | { |
| 108 | int rc; |
| 109 | |
| 110 | rc = cpuhp_setup_state_nocalls(CPUHP_XEN_PREPARE, |
Zhenzhong Duan | eac779a | 2017-10-08 19:58:46 -0700 | [diff] [blame] | 111 | "x86/xen/guest:prepare", |
Vitaly Kuznetsov | e1dab14 | 2017-03-14 18:35:41 +0100 | [diff] [blame] | 112 | cpu_up_prepare_cb, cpu_dead_cb); |
| 113 | if (rc >= 0) { |
| 114 | rc = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, |
Zhenzhong Duan | eac779a | 2017-10-08 19:58:46 -0700 | [diff] [blame] | 115 | "x86/xen/guest:online", |
Vitaly Kuznetsov | e1dab14 | 2017-03-14 18:35:41 +0100 | [diff] [blame] | 116 | xen_cpu_up_online, NULL); |
| 117 | if (rc < 0) |
| 118 | cpuhp_remove_state_nocalls(CPUHP_XEN_PREPARE); |
| 119 | } |
| 120 | |
| 121 | return rc >= 0 ? 0 : rc; |
| 122 | } |
David Vrabel | 1c32cdc | 2012-07-09 11:39:08 +0100 | [diff] [blame] | 123 | |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 124 | static int xen_vcpu_setup_restore(int cpu) |
Ankur Arora | 0b64ffb | 2017-06-02 17:05:59 -0700 | [diff] [blame] | 125 | { |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 126 | int rc = 0; |
| 127 | |
Ankur Arora | 0b64ffb | 2017-06-02 17:05:59 -0700 | [diff] [blame] | 128 | /* Any per_cpu(xen_vcpu) is stale, so reset it */ |
| 129 | xen_vcpu_info_reset(cpu); |
| 130 | |
| 131 | /* |
| 132 | * For PVH and PVHVM, setup online VCPUs only. The rest will |
| 133 | * be handled by hotplug. |
| 134 | */ |
| 135 | if (xen_pv_domain() || |
| 136 | (xen_hvm_domain() && cpu_online(cpu))) { |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 137 | rc = xen_vcpu_setup(cpu); |
Ankur Arora | 0b64ffb | 2017-06-02 17:05:59 -0700 | [diff] [blame] | 138 | } |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 139 | |
| 140 | return rc; |
Ankur Arora | 0b64ffb | 2017-06-02 17:05:59 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Ankur Arora | ad73fd5 | 2017-06-02 17:05:58 -0700 | [diff] [blame] | 143 | /* |
| 144 | * On restore, set the vcpu placement up again. |
| 145 | * If it fails, then we're in a bad state, since |
| 146 | * we can't back out from using it... |
| 147 | */ |
| 148 | void xen_vcpu_restore(void) |
| 149 | { |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 150 | int cpu, rc; |
Ankur Arora | ad73fd5 | 2017-06-02 17:05:58 -0700 | [diff] [blame] | 151 | |
| 152 | for_each_possible_cpu(cpu) { |
| 153 | bool other_cpu = (cpu != smp_processor_id()); |
Ankur Arora | 0b64ffb | 2017-06-02 17:05:59 -0700 | [diff] [blame] | 154 | bool is_up; |
| 155 | |
| 156 | if (xen_vcpu_nr(cpu) == XEN_VCPU_ID_INVALID) |
| 157 | continue; |
| 158 | |
| 159 | /* Only Xen 4.5 and higher support this. */ |
| 160 | is_up = HYPERVISOR_vcpu_op(VCPUOP_is_up, |
| 161 | xen_vcpu_nr(cpu), NULL) > 0; |
Ankur Arora | ad73fd5 | 2017-06-02 17:05:58 -0700 | [diff] [blame] | 162 | |
| 163 | if (other_cpu && is_up && |
| 164 | HYPERVISOR_vcpu_op(VCPUOP_down, xen_vcpu_nr(cpu), NULL)) |
| 165 | BUG(); |
| 166 | |
Ankur Arora | 0b64ffb | 2017-06-02 17:05:59 -0700 | [diff] [blame] | 167 | if (xen_pv_domain() || xen_feature(XENFEAT_hvm_safe_pvclock)) |
| 168 | xen_setup_runstate_info(cpu); |
Ankur Arora | ad73fd5 | 2017-06-02 17:05:58 -0700 | [diff] [blame] | 169 | |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 170 | rc = xen_vcpu_setup_restore(cpu); |
| 171 | if (rc) |
| 172 | pr_emerg_once("vcpu restore failed for cpu=%d err=%d. " |
| 173 | "System will hang.\n", cpu, rc); |
| 174 | /* |
| 175 | * In case xen_vcpu_setup_restore() fails, do not bring up the |
| 176 | * VCPU. This helps us avoid the resulting OOPS when the VCPU |
| 177 | * accesses pvclock_vcpu_time via xen_vcpu (which is NULL.) |
| 178 | * Note that this does not improve the situation much -- now the |
| 179 | * VM hangs instead of OOPSing -- with the VCPUs that did not |
| 180 | * fail, spinning in stop_machine(), waiting for the failed |
| 181 | * VCPUs to come up. |
| 182 | */ |
| 183 | if (other_cpu && is_up && (rc == 0) && |
Ankur Arora | ad73fd5 | 2017-06-02 17:05:58 -0700 | [diff] [blame] | 184 | HYPERVISOR_vcpu_op(VCPUOP_up, xen_vcpu_nr(cpu), NULL)) |
| 185 | BUG(); |
| 186 | } |
| 187 | } |
| 188 | |
Ankur Arora | ad73fd5 | 2017-06-02 17:05:58 -0700 | [diff] [blame] | 189 | void xen_vcpu_info_reset(int cpu) |
| 190 | { |
| 191 | if (xen_vcpu_nr(cpu) < MAX_VIRT_CPUS) { |
| 192 | per_cpu(xen_vcpu, cpu) = |
| 193 | &HYPERVISOR_shared_info->vcpu_info[xen_vcpu_nr(cpu)]; |
| 194 | } else { |
| 195 | /* Set to NULL so that if somebody accesses it we get an OOPS */ |
| 196 | per_cpu(xen_vcpu, cpu) = NULL; |
| 197 | } |
| 198 | } |
| 199 | |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 200 | int xen_vcpu_setup(int cpu) |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 201 | { |
Jeremy Fitzhardinge | 60223a3 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 202 | struct vcpu_register_vcpu_info info; |
| 203 | int err; |
| 204 | struct vcpu_info *vcpup; |
| 205 | |
Jeremy Fitzhardinge | a0d695c | 2008-05-26 23:31:21 +0100 | [diff] [blame] | 206 | BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info); |
Jeremy Fitzhardinge | 60223a3 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 207 | |
Konrad Rzeszutek Wilk | 7f1fc26 | 2013-05-05 09:30:09 -0400 | [diff] [blame] | 208 | /* |
Ankur Arora | 0b64ffb | 2017-06-02 17:05:59 -0700 | [diff] [blame] | 209 | * This path is called on PVHVM at bootup (xen_hvm_smp_prepare_boot_cpu) |
| 210 | * and at restore (xen_vcpu_restore). Also called for hotplugged |
| 211 | * VCPUs (cpu_init -> xen_hvm_cpu_prepare_hvm). |
| 212 | * However, the hypercall can only be done once (see below) so if a VCPU |
| 213 | * is offlined and comes back online then let's not redo the hypercall. |
Konrad Rzeszutek Wilk | 7f1fc26 | 2013-05-05 09:30:09 -0400 | [diff] [blame] | 214 | * |
| 215 | * For PV it is called during restore (xen_vcpu_restore) and bootup |
| 216 | * (xen_setup_vcpu_info_placement). The hotplug mechanism does not |
| 217 | * use this function. |
| 218 | */ |
| 219 | if (xen_hvm_domain()) { |
| 220 | if (per_cpu(xen_vcpu, cpu) == &per_cpu(xen_vcpu_info, cpu)) |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 221 | return 0; |
Konrad Rzeszutek Wilk | 7f1fc26 | 2013-05-05 09:30:09 -0400 | [diff] [blame] | 222 | } |
Ankur Arora | ad73fd5 | 2017-06-02 17:05:58 -0700 | [diff] [blame] | 223 | |
Ankur Arora | ad73fd5 | 2017-06-02 17:05:58 -0700 | [diff] [blame] | 224 | if (xen_have_vcpu_info_placement) { |
| 225 | vcpup = &per_cpu(xen_vcpu_info, cpu); |
| 226 | info.mfn = arbitrary_virt_to_mfn(vcpup); |
| 227 | info.offset = offset_in_page(vcpup); |
| 228 | |
| 229 | /* |
| 230 | * Check to see if the hypervisor will put the vcpu_info |
| 231 | * structure where we want it, which allows direct access via |
| 232 | * a percpu-variable. |
| 233 | * N.B. This hypercall can _only_ be called once per CPU. |
| 234 | * Subsequent calls will error out with -EINVAL. This is due to |
| 235 | * the fact that hypervisor has no unregister variant and this |
| 236 | * hypercall does not allow to over-write info.mfn and |
| 237 | * info.offset. |
| 238 | */ |
| 239 | err = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_info, |
| 240 | xen_vcpu_nr(cpu), &info); |
| 241 | |
| 242 | if (err) { |
| 243 | pr_warn_once("register_vcpu_info failed: cpu=%d err=%d\n", |
| 244 | cpu, err); |
| 245 | xen_have_vcpu_info_placement = 0; |
| 246 | } else { |
| 247 | /* |
| 248 | * This cpu is using the registered vcpu info, even if |
| 249 | * later ones fail to. |
| 250 | */ |
| 251 | per_cpu(xen_vcpu, cpu) = vcpup; |
| 252 | } |
| 253 | } |
Mukesh Rathor | c06ee78 | 2010-07-19 10:25:08 -0700 | [diff] [blame] | 254 | |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 255 | if (!xen_have_vcpu_info_placement) |
Ankur Arora | 0b64ffb | 2017-06-02 17:05:59 -0700 | [diff] [blame] | 256 | xen_vcpu_info_reset(cpu); |
Ankur Arora | c9b5d98 | 2017-06-02 17:06:01 -0700 | [diff] [blame] | 257 | |
| 258 | return ((per_cpu(xen_vcpu, cpu) == NULL) ? -ENODEV : 0); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Vitaly Kuznetsov | 98f2a47 | 2017-03-14 18:35:40 +0100 | [diff] [blame] | 261 | void xen_reboot(int reason) |
Jeremy Fitzhardinge | fefa629 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 262 | { |
Jeremy Fitzhardinge | 349c709f | 2008-05-26 23:31:02 +0100 | [diff] [blame] | 263 | struct sched_shutdown r = { .reason = reason }; |
Boris Ostrovsky | 65d0cf0 | 2015-08-10 16:34:34 -0400 | [diff] [blame] | 264 | int cpu; |
| 265 | |
| 266 | for_each_online_cpu(cpu) |
| 267 | xen_pmu_finish(cpu); |
Jeremy Fitzhardinge | 349c709f | 2008-05-26 23:31:02 +0100 | [diff] [blame] | 268 | |
Jeremy Fitzhardinge | 349c709f | 2008-05-26 23:31:02 +0100 | [diff] [blame] | 269 | if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r)) |
Jeremy Fitzhardinge | fefa629 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 270 | BUG(); |
| 271 | } |
| 272 | |
Boris Ostrovsky | c6875f3 | 2019-09-30 16:44:41 -0400 | [diff] [blame] | 273 | static int reboot_reason = SHUTDOWN_reboot; |
| 274 | static bool xen_legacy_crash; |
Vitaly Kuznetsov | 98f2a47 | 2017-03-14 18:35:40 +0100 | [diff] [blame] | 275 | void xen_emergency_restart(void) |
Jeremy Fitzhardinge | fefa629 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 276 | { |
Boris Ostrovsky | c6875f3 | 2019-09-30 16:44:41 -0400 | [diff] [blame] | 277 | xen_reboot(reboot_reason); |
Jeremy Fitzhardinge | fefa629 | 2007-07-17 18:37:07 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Donald Dutile | f09f6d1 | 2010-07-15 14:56:49 -0400 | [diff] [blame] | 280 | static int |
| 281 | xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 282 | { |
Boris Ostrovsky | c6875f3 | 2019-09-30 16:44:41 -0400 | [diff] [blame] | 283 | if (!kexec_crash_loaded()) { |
| 284 | if (xen_legacy_crash) |
| 285 | xen_reboot(SHUTDOWN_crash); |
| 286 | |
| 287 | reboot_reason = SHUTDOWN_crash; |
| 288 | |
| 289 | /* |
| 290 | * If panic_timeout==0 then we are supposed to wait forever. |
| 291 | * However, to preserve original dom0 behavior we have to drop |
| 292 | * into hypervisor. (domU behavior is controlled by its |
| 293 | * config file) |
| 294 | */ |
| 295 | if (panic_timeout == 0) |
| 296 | panic_timeout = -1; |
| 297 | } |
Donald Dutile | f09f6d1 | 2010-07-15 14:56:49 -0400 | [diff] [blame] | 298 | return NOTIFY_DONE; |
| 299 | } |
| 300 | |
Boris Ostrovsky | c6875f3 | 2019-09-30 16:44:41 -0400 | [diff] [blame] | 301 | static int __init parse_xen_legacy_crash(char *arg) |
| 302 | { |
| 303 | xen_legacy_crash = true; |
| 304 | return 0; |
| 305 | } |
| 306 | early_param("xen_legacy_crash", parse_xen_legacy_crash); |
| 307 | |
Donald Dutile | f09f6d1 | 2010-07-15 14:56:49 -0400 | [diff] [blame] | 308 | static struct notifier_block xen_panic_block = { |
Vitaly Kuznetsov | e1dab14 | 2017-03-14 18:35:41 +0100 | [diff] [blame] | 309 | .notifier_call = xen_panic_event, |
Radim Krčmář | bc5eb20 | 2014-05-13 18:56:25 +0200 | [diff] [blame] | 310 | .priority = INT_MIN |
Donald Dutile | f09f6d1 | 2010-07-15 14:56:49 -0400 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | int xen_panic_handler_init(void) |
| 314 | { |
| 315 | atomic_notifier_chain_register(&panic_notifier_list, &xen_panic_block); |
| 316 | return 0; |
| 317 | } |
| 318 | |
Vitaly Kuznetsov | 98f2a47 | 2017-03-14 18:35:40 +0100 | [diff] [blame] | 319 | void xen_pin_vcpu(int cpu) |
Juergen Gross | 99bc675 | 2016-08-29 08:48:45 +0200 | [diff] [blame] | 320 | { |
| 321 | static bool disable_pinning; |
| 322 | struct sched_pin_override pin_override; |
| 323 | int ret; |
| 324 | |
| 325 | if (disable_pinning) |
| 326 | return; |
| 327 | |
| 328 | pin_override.pcpu = cpu; |
| 329 | ret = HYPERVISOR_sched_op(SCHEDOP_pin_override, &pin_override); |
| 330 | |
| 331 | /* Ignore errors when removing override. */ |
| 332 | if (cpu < 0) |
| 333 | return; |
| 334 | |
| 335 | switch (ret) { |
| 336 | case -ENOSYS: |
| 337 | pr_warn("Unable to pin on physical cpu %d. In case of problems consider vcpu pinning.\n", |
| 338 | cpu); |
| 339 | disable_pinning = true; |
| 340 | break; |
| 341 | case -EPERM: |
| 342 | WARN(1, "Trying to pin vcpu without having privilege to do so\n"); |
| 343 | disable_pinning = true; |
| 344 | break; |
| 345 | case -EINVAL: |
| 346 | case -EBUSY: |
| 347 | pr_warn("Physical cpu %d not available for pinning. Check Xen cpu configuration.\n", |
| 348 | cpu); |
| 349 | break; |
| 350 | case 0: |
| 351 | break; |
| 352 | default: |
| 353 | WARN(1, "rc %d while trying to pin vcpu\n", ret); |
| 354 | disable_pinning = true; |
| 355 | } |
| 356 | } |
| 357 | |
Stefano Stabellini | a314e3e | 2015-10-22 16:20:46 +0000 | [diff] [blame] | 358 | #ifdef CONFIG_HOTPLUG_CPU |
| 359 | void xen_arch_register_cpu(int num) |
| 360 | { |
| 361 | arch_register_cpu(num); |
| 362 | } |
| 363 | EXPORT_SYMBOL(xen_arch_register_cpu); |
| 364 | |
| 365 | void xen_arch_unregister_cpu(int num) |
| 366 | { |
| 367 | arch_unregister_cpu(num); |
| 368 | } |
| 369 | EXPORT_SYMBOL(xen_arch_unregister_cpu); |
| 370 | #endif |