Thomas Gleixner | 3b20eb2 | 2019-05-29 16:57:35 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2 | /* |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 3 | * Copyright (c) 2009, Microsoft Corporation. |
| 4 | * |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 5 | * Authors: |
| 6 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 7 | * Hank Janssen <hjanssen@microsoft.com> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 8 | */ |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 10 | |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 11 | #include <linux/kernel.h> |
| 12 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Bill Pemberton | b7c947f | 2009-07-29 17:00:13 -0400 | [diff] [blame] | 14 | #include <linux/vmalloc.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 15 | #include <linux/hyperv.h> |
K. Y. Srinivasan | 83ba0c4 | 2012-07-24 16:11:58 -0700 | [diff] [blame] | 16 | #include <linux/version.h> |
Michael Kelley | 248e742 | 2018-03-04 22:17:18 -0700 | [diff] [blame] | 17 | #include <linux/random.h> |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 18 | #include <linux/clockchips.h> |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame^] | 19 | #include <clocksource/hyperv_timer.h> |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 20 | #include <asm/mshyperv.h> |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 21 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 22 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 23 | /* The one and only */ |
K. Y. Srinivasan | a3cadf3 | 2018-10-18 05:09:28 +0000 | [diff] [blame] | 24 | struct hv_context hv_context; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 25 | |
Michael Kelley | 248e742 | 2018-03-04 22:17:18 -0700 | [diff] [blame] | 26 | /* |
Haiyang Zhang | d44890c | 2010-11-08 14:04:42 -0800 | [diff] [blame] | 27 | * hv_init - Main initialization routine. |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 28 | * |
| 29 | * This routine must be called before any other routines in here are called |
| 30 | */ |
Haiyang Zhang | d44890c | 2010-11-08 14:04:42 -0800 | [diff] [blame] | 31 | int hv_init(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 32 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 33 | hv_context.cpu_context = alloc_percpu(struct hv_per_cpu_context); |
| 34 | if (!hv_context.cpu_context) |
| 35 | return -ENOMEM; |
K. Y. Srinivasan | 5433e00 | 2011-08-25 09:48:51 -0700 | [diff] [blame] | 36 | return 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 39 | /* |
Haiyang Zhang | d44890c | 2010-11-08 14:04:42 -0800 | [diff] [blame] | 40 | * hv_post_message - Post a message using the hypervisor message IPC. |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 41 | * |
| 42 | * This involves a hypercall. |
| 43 | */ |
Dan Carpenter | 415f0a0 | 2012-03-28 09:58:07 +0300 | [diff] [blame] | 44 | int hv_post_message(union hv_connection_id connection_id, |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 45 | enum hv_message_type message_type, |
| 46 | void *payload, size_t payload_size) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 47 | { |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 48 | struct hv_input_post_message *aligned_msg; |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 49 | struct hv_per_cpu_context *hv_cpu; |
Jake Oshins | a108393 | 2015-12-14 16:01:40 -0800 | [diff] [blame] | 50 | u64 status; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 51 | |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 52 | if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT) |
K. Y. Srinivasan | 39594ab | 2011-06-06 15:50:09 -0700 | [diff] [blame] | 53 | return -EMSGSIZE; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 54 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 55 | hv_cpu = get_cpu_ptr(hv_context.cpu_context); |
| 56 | aligned_msg = hv_cpu->post_msg_page; |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 57 | aligned_msg->connectionid = connection_id; |
K. Y. Srinivasan | b29ef35 | 2014-08-28 18:29:52 -0700 | [diff] [blame] | 58 | aligned_msg->reserved = 0; |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 59 | aligned_msg->message_type = message_type; |
| 60 | aligned_msg->payload_size = payload_size; |
| 61 | memcpy((void *)aligned_msg->payload, payload, payload_size); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 62 | |
Jake Oshins | a108393 | 2015-12-14 16:01:40 -0800 | [diff] [blame] | 63 | status = hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 64 | |
Michael Kelley | 13b9abf | 2017-05-18 10:46:07 -0700 | [diff] [blame] | 65 | /* Preemption must remain disabled until after the hypercall |
| 66 | * so some other thread can't get scheduled onto this cpu and |
| 67 | * corrupt the per-cpu post_msg_page |
| 68 | */ |
| 69 | put_cpu_ptr(hv_cpu); |
| 70 | |
Jake Oshins | a108393 | 2015-12-14 16:01:40 -0800 | [diff] [blame] | 71 | return status & 0xFFFF; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 74 | int hv_synic_alloc(void) |
| 75 | { |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 76 | int cpu; |
Michael Kelley | f25a7ec | 2018-08-10 23:06:11 +0000 | [diff] [blame] | 77 | struct hv_per_cpu_context *hv_cpu; |
| 78 | |
| 79 | /* |
| 80 | * First, zero all per-cpu memory areas so hv_synic_free() can |
| 81 | * detect what memory has been allocated and cleanup properly |
| 82 | * after any failures. |
| 83 | */ |
| 84 | for_each_present_cpu(cpu) { |
| 85 | hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); |
| 86 | memset(hv_cpu, 0, sizeof(*hv_cpu)); |
| 87 | } |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 88 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 89 | hv_context.hv_numa_map = kcalloc(nr_node_ids, sizeof(struct cpumask), |
Jia-Ju Bai | 597ff72 | 2018-03-04 22:17:12 -0700 | [diff] [blame] | 90 | GFP_KERNEL); |
K. Y. Srinivasan | 9f01ec5 | 2015-08-05 00:52:38 -0700 | [diff] [blame] | 91 | if (hv_context.hv_numa_map == NULL) { |
| 92 | pr_err("Unable to allocate NUMA map\n"); |
| 93 | goto err; |
| 94 | } |
| 95 | |
Vitaly Kuznetsov | 421b8f2 | 2016-12-07 01:16:25 -0800 | [diff] [blame] | 96 | for_each_present_cpu(cpu) { |
Michael Kelley | f25a7ec | 2018-08-10 23:06:11 +0000 | [diff] [blame] | 97 | hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 98 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 99 | tasklet_init(&hv_cpu->msg_dpc, |
| 100 | vmbus_on_msg_dpc, (unsigned long) hv_cpu); |
K. Y. Srinivasan | d81274a | 2016-02-26 15:13:21 -0800 | [diff] [blame] | 101 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 102 | hv_cpu->synic_message_page = |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 103 | (void *)get_zeroed_page(GFP_ATOMIC); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 104 | if (hv_cpu->synic_message_page == NULL) { |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 105 | pr_err("Unable to allocate SYNIC message page\n"); |
| 106 | goto err; |
| 107 | } |
| 108 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 109 | hv_cpu->synic_event_page = (void *)get_zeroed_page(GFP_ATOMIC); |
| 110 | if (hv_cpu->synic_event_page == NULL) { |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 111 | pr_err("Unable to allocate SYNIC event page\n"); |
| 112 | goto err; |
| 113 | } |
K. Y. Srinivasan | b29ef35 | 2014-08-28 18:29:52 -0700 | [diff] [blame] | 114 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 115 | hv_cpu->post_msg_page = (void *)get_zeroed_page(GFP_ATOMIC); |
| 116 | if (hv_cpu->post_msg_page == NULL) { |
K. Y. Srinivasan | b29ef35 | 2014-08-28 18:29:52 -0700 | [diff] [blame] | 117 | pr_err("Unable to allocate post msg page\n"); |
| 118 | goto err; |
| 119 | } |
Vitaly Kuznetsov | 3c7630d | 2016-12-07 01:16:26 -0800 | [diff] [blame] | 120 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 121 | INIT_LIST_HEAD(&hv_cpu->chan_list); |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | return 0; |
| 125 | err: |
Michael Kelley | 5720863 | 2018-08-02 03:08:25 +0000 | [diff] [blame] | 126 | /* |
| 127 | * Any memory allocations that succeeded will be freed when |
| 128 | * the caller cleans up by calling hv_synic_free() |
| 129 | */ |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 130 | return -ENOMEM; |
| 131 | } |
| 132 | |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 133 | |
| 134 | void hv_synic_free(void) |
| 135 | { |
| 136 | int cpu; |
| 137 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 138 | for_each_present_cpu(cpu) { |
| 139 | struct hv_per_cpu_context *hv_cpu |
| 140 | = per_cpu_ptr(hv_context.cpu_context, cpu); |
| 141 | |
Michael Kelley | 5720863 | 2018-08-02 03:08:25 +0000 | [diff] [blame] | 142 | free_page((unsigned long)hv_cpu->synic_event_page); |
| 143 | free_page((unsigned long)hv_cpu->synic_message_page); |
| 144 | free_page((unsigned long)hv_cpu->post_msg_page); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 145 | } |
| 146 | |
K. Y. Srinivasan | 9f01ec5 | 2015-08-05 00:52:38 -0700 | [diff] [blame] | 147 | kfree(hv_context.hv_numa_map); |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 148 | } |
| 149 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 150 | /* |
Joe Perches | 68cb811 | 2018-03-04 22:17:13 -0700 | [diff] [blame] | 151 | * hv_synic_init - Initialize the Synthetic Interrupt Controller. |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 152 | * |
| 153 | * If it is already initialized by another entity (ie x2v shim), we need to |
| 154 | * retrieve the initialized message and event pages. Otherwise, we create and |
| 155 | * initialize the message and event pages. |
| 156 | */ |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 157 | int hv_synic_init(unsigned int cpu) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 158 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 159 | struct hv_per_cpu_context *hv_cpu |
| 160 | = per_cpu_ptr(hv_context.cpu_context, cpu); |
Greg Kroah-Hartman | eacb1b4 | 2009-08-20 12:11:26 -0700 | [diff] [blame] | 161 | union hv_synic_simp simp; |
| 162 | union hv_synic_siefp siefp; |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 163 | union hv_synic_sint shared_sint; |
Greg Kroah-Hartman | eacb1b4 | 2009-08-20 12:11:26 -0700 | [diff] [blame] | 164 | union hv_synic_scontrol sctrl; |
Hank Janssen | a73e6b7 | 2010-01-22 19:17:50 +0000 | [diff] [blame] | 165 | |
Hank Janssen | a73e6b7 | 2010-01-22 19:17:50 +0000 | [diff] [blame] | 166 | /* Setup the Synic's message page */ |
K. Y. Srinivasan | 155e4a2 | 2017-01-19 11:51:54 -0700 | [diff] [blame] | 167 | hv_get_simp(simp.as_uint64); |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 168 | simp.simp_enabled = 1; |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 169 | simp.base_simp_gpa = virt_to_phys(hv_cpu->synic_message_page) |
Hank Janssen | a73e6b7 | 2010-01-22 19:17:50 +0000 | [diff] [blame] | 170 | >> PAGE_SHIFT; |
| 171 | |
K. Y. Srinivasan | 155e4a2 | 2017-01-19 11:51:54 -0700 | [diff] [blame] | 172 | hv_set_simp(simp.as_uint64); |
Hank Janssen | a73e6b7 | 2010-01-22 19:17:50 +0000 | [diff] [blame] | 173 | |
| 174 | /* Setup the Synic's event page */ |
K. Y. Srinivasan | 8e307bf | 2017-01-19 11:51:55 -0700 | [diff] [blame] | 175 | hv_get_siefp(siefp.as_uint64); |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 176 | siefp.siefp_enabled = 1; |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 177 | siefp.base_siefp_gpa = virt_to_phys(hv_cpu->synic_event_page) |
Hank Janssen | a73e6b7 | 2010-01-22 19:17:50 +0000 | [diff] [blame] | 178 | >> PAGE_SHIFT; |
| 179 | |
K. Y. Srinivasan | 8e307bf | 2017-01-19 11:51:55 -0700 | [diff] [blame] | 180 | hv_set_siefp(siefp.as_uint64); |
Hank Janssen | a73e6b7 | 2010-01-22 19:17:50 +0000 | [diff] [blame] | 181 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 182 | /* Setup the shared SINT. */ |
Michael Kelley | 619a4c8 | 2018-06-05 13:37:53 -0700 | [diff] [blame] | 183 | hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 184 | |
K. Y. Srinivasan | 302a3c0 | 2013-02-17 11:30:44 -0800 | [diff] [blame] | 185 | shared_sint.vector = HYPERVISOR_CALLBACK_VECTOR; |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 186 | shared_sint.masked = false; |
Michael Kelley | 7dc9b6b | 2018-06-05 13:37:54 -0700 | [diff] [blame] | 187 | if (ms_hyperv.hints & HV_DEPRECATING_AEOI_RECOMMENDED) |
K. Y. Srinivasan | 6c248aa | 2017-03-14 18:01:39 -0700 | [diff] [blame] | 188 | shared_sint.auto_eoi = false; |
| 189 | else |
| 190 | shared_sint.auto_eoi = true; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 191 | |
Michael Kelley | 619a4c8 | 2018-06-05 13:37:53 -0700 | [diff] [blame] | 192 | hv_set_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 193 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 194 | /* Enable the global synic bit */ |
K. Y. Srinivasan | 06d1d98 | 2017-01-19 11:51:56 -0700 | [diff] [blame] | 195 | hv_get_synic_state(sctrl.as_uint64); |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 196 | sctrl.enable = 1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 197 | |
K. Y. Srinivasan | 06d1d98 | 2017-01-19 11:51:56 -0700 | [diff] [blame] | 198 | hv_set_synic_state(sctrl.as_uint64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 199 | |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame^] | 200 | hv_stimer_init(cpu); |
| 201 | |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 202 | return 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 205 | /* |
Haiyang Zhang | d44890c | 2010-11-08 14:04:42 -0800 | [diff] [blame] | 206 | * hv_synic_cleanup - Cleanup routine for hv_synic_init(). |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 207 | */ |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 208 | int hv_synic_cleanup(unsigned int cpu) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 209 | { |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 210 | union hv_synic_sint shared_sint; |
Greg Kroah-Hartman | eacb1b4 | 2009-08-20 12:11:26 -0700 | [diff] [blame] | 211 | union hv_synic_simp simp; |
| 212 | union hv_synic_siefp siefp; |
Vitaly Kuznetsov | e72e7ac | 2015-02-27 11:25:55 -0800 | [diff] [blame] | 213 | union hv_synic_scontrol sctrl; |
Vitaly Kuznetsov | 523b940 | 2016-12-07 14:53:12 -0800 | [diff] [blame] | 214 | struct vmbus_channel *channel, *sc; |
| 215 | bool channel_found = false; |
| 216 | unsigned long flags; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 217 | |
K. Y. Srinivasan | a3cadf3 | 2018-10-18 05:09:28 +0000 | [diff] [blame] | 218 | hv_get_synic_state(sctrl.as_uint64); |
| 219 | if (sctrl.enable != 1) |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 220 | return -EFAULT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 221 | |
Vitaly Kuznetsov | 523b940 | 2016-12-07 14:53:12 -0800 | [diff] [blame] | 222 | /* |
| 223 | * Search for channels which are bound to the CPU we're about to |
| 224 | * cleanup. In case we find one and vmbus is still connected we need to |
| 225 | * fail, this will effectively prevent CPU offlining. There is no way |
| 226 | * we can re-bind channels to different CPUs for now. |
| 227 | */ |
| 228 | mutex_lock(&vmbus_connection.channel_mutex); |
| 229 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
| 230 | if (channel->target_cpu == cpu) { |
| 231 | channel_found = true; |
| 232 | break; |
| 233 | } |
| 234 | spin_lock_irqsave(&channel->lock, flags); |
| 235 | list_for_each_entry(sc, &channel->sc_list, sc_list) { |
| 236 | if (sc->target_cpu == cpu) { |
| 237 | channel_found = true; |
| 238 | break; |
| 239 | } |
| 240 | } |
| 241 | spin_unlock_irqrestore(&channel->lock, flags); |
| 242 | if (channel_found) |
| 243 | break; |
| 244 | } |
| 245 | mutex_unlock(&vmbus_connection.channel_mutex); |
| 246 | |
| 247 | if (channel_found && vmbus_connection.conn_state == CONNECTED) |
| 248 | return -EBUSY; |
| 249 | |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame^] | 250 | hv_stimer_cleanup(cpu); |
Vitaly Kuznetsov | e086748 | 2015-02-27 11:25:57 -0800 | [diff] [blame] | 251 | |
Michael Kelley | 619a4c8 | 2018-06-05 13:37:53 -0700 | [diff] [blame] | 252 | hv_get_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 253 | |
Haiyang Zhang | b8dfb26 | 2010-11-08 14:04:41 -0800 | [diff] [blame] | 254 | shared_sint.masked = 1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 255 | |
Greg Kroah-Hartman | 7692fd4 | 2010-01-08 09:06:40 -0800 | [diff] [blame] | 256 | /* Need to correctly cleanup in the case of SMP!!! */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 257 | /* Disable the interrupt */ |
Michael Kelley | 619a4c8 | 2018-06-05 13:37:53 -0700 | [diff] [blame] | 258 | hv_set_synint_state(VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 259 | |
K. Y. Srinivasan | 155e4a2 | 2017-01-19 11:51:54 -0700 | [diff] [blame] | 260 | hv_get_simp(simp.as_uint64); |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 261 | simp.simp_enabled = 0; |
| 262 | simp.base_simp_gpa = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 263 | |
K. Y. Srinivasan | 155e4a2 | 2017-01-19 11:51:54 -0700 | [diff] [blame] | 264 | hv_set_simp(simp.as_uint64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 265 | |
K. Y. Srinivasan | 8e307bf | 2017-01-19 11:51:55 -0700 | [diff] [blame] | 266 | hv_get_siefp(siefp.as_uint64); |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 267 | siefp.siefp_enabled = 0; |
| 268 | siefp.base_siefp_gpa = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 269 | |
K. Y. Srinivasan | 8e307bf | 2017-01-19 11:51:55 -0700 | [diff] [blame] | 270 | hv_set_siefp(siefp.as_uint64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 271 | |
Vitaly Kuznetsov | e72e7ac | 2015-02-27 11:25:55 -0800 | [diff] [blame] | 272 | /* Disable the global synic bit */ |
Vitaly Kuznetsov | e72e7ac | 2015-02-27 11:25:55 -0800 | [diff] [blame] | 273 | sctrl.enable = 0; |
K. Y. Srinivasan | 06d1d98 | 2017-01-19 11:51:56 -0700 | [diff] [blame] | 274 | hv_set_synic_state(sctrl.as_uint64); |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 275 | |
| 276 | return 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 277 | } |