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> |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 8 | * K. Y. Srinivasan <kys@microsoft.com> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 9 | */ |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/device.h> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/sysctl.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 18 | #include <linux/acpi.h> |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 19 | #include <linux/completion.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 20 | #include <linux/hyperv.h> |
K. Y. Srinivasan | b020950 | 2012-12-01 06:46:54 -0800 | [diff] [blame] | 21 | #include <linux/kernel_stat.h> |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 22 | #include <linux/clockchips.h> |
Vitaly Kuznetsov | e513229 | 2015-02-27 11:25:51 -0800 | [diff] [blame] | 23 | #include <linux/cpu.h> |
Ingo Molnar | 68db0cf | 2017-02-08 18:51:37 +0100 | [diff] [blame] | 24 | #include <linux/sched/task_stack.h> |
| 25 | |
K. Y. Srinivasan | 302a3c0 | 2013-02-17 11:30:44 -0800 | [diff] [blame] | 26 | #include <asm/mshyperv.h> |
Dexuan Cui | 1f48dcf | 2019-09-05 23:01:20 +0000 | [diff] [blame] | 27 | #include <linux/delay.h> |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 28 | #include <linux/notifier.h> |
| 29 | #include <linux/ptrace.h> |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 30 | #include <linux/screen_info.h> |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 31 | #include <linux/kdebug.h> |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 32 | #include <linux/efi.h> |
Stephan Mueller | 4b44f2d | 2016-05-02 02:14:34 -0400 | [diff] [blame] | 33 | #include <linux/random.h> |
Tianyu Lan | f3a99e7 | 2020-04-06 08:53:31 -0700 | [diff] [blame] | 34 | #include <linux/kernel.h> |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame] | 35 | #include <linux/syscore_ops.h> |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 36 | #include <clocksource/hyperv_timer.h> |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 37 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 38 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 39 | struct vmbus_dynid { |
| 40 | struct list_head node; |
| 41 | struct hv_vmbus_device_id id; |
| 42 | }; |
| 43 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 44 | static struct acpi_device *hv_acpi_dev; |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 45 | |
K. Y. Srinivasan | 71a6655 | 2011-04-29 13:45:04 -0700 | [diff] [blame] | 46 | static struct completion probe_event; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 47 | |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 48 | static int hyperv_cpuhp_online; |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 49 | |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 50 | static void *hv_panic_page; |
| 51 | |
Tianyu Lan | 040026d | 2020-04-06 08:53:30 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Boolean to control whether to report panic messages over Hyper-V. |
| 54 | * |
| 55 | * It can be set via /proc/sys/kernel/hyperv/record_panic_msg |
| 56 | */ |
| 57 | static int sysctl_record_panic_msg = 1; |
| 58 | |
| 59 | static int hyperv_report_reg(void) |
| 60 | { |
| 61 | return !sysctl_record_panic_msg || !hv_panic_page; |
| 62 | } |
| 63 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 64 | static int hyperv_panic_event(struct notifier_block *nb, unsigned long val, |
| 65 | void *args) |
| 66 | { |
| 67 | struct pt_regs *regs; |
| 68 | |
Tianyu Lan | 74347a9 | 2020-04-06 08:53:26 -0700 | [diff] [blame] | 69 | vmbus_initiate_unload(true); |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 70 | |
Tianyu Lan | 73f26e5 | 2020-04-06 08:53:28 -0700 | [diff] [blame] | 71 | /* |
| 72 | * Hyper-V should be notified only once about a panic. If we will be |
| 73 | * doing hyperv_report_panic_msg() later with kmsg data, don't do |
| 74 | * the notification here. |
| 75 | */ |
| 76 | if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE |
Tianyu Lan | 040026d | 2020-04-06 08:53:30 -0700 | [diff] [blame] | 77 | && hyperv_report_reg()) { |
Tianyu Lan | 74347a9 | 2020-04-06 08:53:26 -0700 | [diff] [blame] | 78 | regs = current_pt_regs(); |
Tianyu Lan | f3a99e7 | 2020-04-06 08:53:31 -0700 | [diff] [blame] | 79 | hyperv_report_panic(regs, val, false); |
Tianyu Lan | 74347a9 | 2020-04-06 08:53:26 -0700 | [diff] [blame] | 80 | } |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 81 | return NOTIFY_DONE; |
| 82 | } |
| 83 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 84 | static int hyperv_die_event(struct notifier_block *nb, unsigned long val, |
| 85 | void *args) |
| 86 | { |
| 87 | struct die_args *die = (struct die_args *)args; |
| 88 | struct pt_regs *regs = die->regs; |
| 89 | |
Tianyu Lan | 73f26e5 | 2020-04-06 08:53:28 -0700 | [diff] [blame] | 90 | /* |
| 91 | * Hyper-V should be notified only once about a panic. If we will be |
| 92 | * doing hyperv_report_panic_msg() later with kmsg data, don't do |
| 93 | * the notification here. |
| 94 | */ |
Tianyu Lan | 040026d | 2020-04-06 08:53:30 -0700 | [diff] [blame] | 95 | if (hyperv_report_reg()) |
Tianyu Lan | f3a99e7 | 2020-04-06 08:53:31 -0700 | [diff] [blame] | 96 | hyperv_report_panic(regs, val, true); |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 97 | return NOTIFY_DONE; |
| 98 | } |
| 99 | |
| 100 | static struct notifier_block hyperv_die_block = { |
| 101 | .notifier_call = hyperv_die_event, |
| 102 | }; |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 103 | static struct notifier_block hyperv_panic_block = { |
| 104 | .notifier_call = hyperv_panic_event, |
| 105 | }; |
| 106 | |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 107 | static const char *fb_mmio_name = "fb_range"; |
| 108 | static struct resource *fb_mmio; |
Stephen Hemminger | e2e8084 | 2016-09-07 05:39:33 -0700 | [diff] [blame] | 109 | static struct resource *hyperv_mmio; |
Davidlohr Bueso | 8aea7f8 | 2019-11-01 13:00:04 -0700 | [diff] [blame] | 110 | static DEFINE_MUTEX(hyperv_mmio_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 111 | |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 112 | static int vmbus_exists(void) |
| 113 | { |
| 114 | if (hv_acpi_dev == NULL) |
| 115 | return -ENODEV; |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 120 | #define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)->guid) * 2) |
| 121 | static void print_alias_name(struct hv_device *hv_dev, char *alias_name) |
| 122 | { |
| 123 | int i; |
| 124 | for (i = 0; i < VMBUS_ALIAS_LEN; i += 2) |
| 125 | sprintf(&alias_name[i], "%02x", hv_dev->dev_type.b[i/2]); |
| 126 | } |
| 127 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 128 | static u8 channel_monitor_group(const struct vmbus_channel *channel) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 129 | { |
| 130 | return (u8)channel->offermsg.monitorid / 32; |
| 131 | } |
| 132 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 133 | static u8 channel_monitor_offset(const struct vmbus_channel *channel) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 134 | { |
| 135 | return (u8)channel->offermsg.monitorid % 32; |
| 136 | } |
| 137 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 138 | static u32 channel_pending(const struct vmbus_channel *channel, |
| 139 | const struct hv_monitor_page *monitor_page) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 140 | { |
| 141 | u8 monitor_group = channel_monitor_group(channel); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 142 | |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 143 | return monitor_page->trigger_group[monitor_group].pending; |
| 144 | } |
| 145 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 146 | static u32 channel_latency(const struct vmbus_channel *channel, |
| 147 | const struct hv_monitor_page *monitor_page) |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 148 | { |
| 149 | u8 monitor_group = channel_monitor_group(channel); |
| 150 | u8 monitor_offset = channel_monitor_offset(channel); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 151 | |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 152 | return monitor_page->latency[monitor_group][monitor_offset]; |
| 153 | } |
| 154 | |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 155 | static u32 channel_conn_id(struct vmbus_channel *channel, |
| 156 | struct hv_monitor_page *monitor_page) |
| 157 | { |
| 158 | u8 monitor_group = channel_monitor_group(channel); |
| 159 | u8 monitor_offset = channel_monitor_offset(channel); |
| 160 | return monitor_page->parameter[monitor_group][monitor_offset].connectionid.u.id; |
| 161 | } |
| 162 | |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 163 | static ssize_t id_show(struct device *dev, struct device_attribute *dev_attr, |
| 164 | char *buf) |
| 165 | { |
| 166 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 167 | |
| 168 | if (!hv_dev->channel) |
| 169 | return -ENODEV; |
| 170 | return sprintf(buf, "%d\n", hv_dev->channel->offermsg.child_relid); |
| 171 | } |
| 172 | static DEVICE_ATTR_RO(id); |
| 173 | |
Greg Kroah-Hartman | a8fb5f3 | 2013-09-13 11:32:50 -0700 | [diff] [blame] | 174 | static ssize_t state_show(struct device *dev, struct device_attribute *dev_attr, |
| 175 | char *buf) |
| 176 | { |
| 177 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 178 | |
| 179 | if (!hv_dev->channel) |
| 180 | return -ENODEV; |
| 181 | return sprintf(buf, "%d\n", hv_dev->channel->state); |
| 182 | } |
| 183 | static DEVICE_ATTR_RO(state); |
| 184 | |
Greg Kroah-Hartman | 5ffd00e | 2013-09-13 11:32:51 -0700 | [diff] [blame] | 185 | static ssize_t monitor_id_show(struct device *dev, |
| 186 | struct device_attribute *dev_attr, char *buf) |
| 187 | { |
| 188 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 189 | |
| 190 | if (!hv_dev->channel) |
| 191 | return -ENODEV; |
| 192 | return sprintf(buf, "%d\n", hv_dev->channel->offermsg.monitorid); |
| 193 | } |
| 194 | static DEVICE_ATTR_RO(monitor_id); |
| 195 | |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 196 | static ssize_t class_id_show(struct device *dev, |
| 197 | struct device_attribute *dev_attr, char *buf) |
| 198 | { |
| 199 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 200 | |
| 201 | if (!hv_dev->channel) |
| 202 | return -ENODEV; |
| 203 | return sprintf(buf, "{%pUl}\n", |
| 204 | hv_dev->channel->offermsg.offer.if_type.b); |
| 205 | } |
| 206 | static DEVICE_ATTR_RO(class_id); |
| 207 | |
Greg Kroah-Hartman | 7c55e1d | 2013-09-13 11:32:54 -0700 | [diff] [blame] | 208 | static ssize_t device_id_show(struct device *dev, |
| 209 | struct device_attribute *dev_attr, char *buf) |
| 210 | { |
| 211 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 212 | |
| 213 | if (!hv_dev->channel) |
| 214 | return -ENODEV; |
| 215 | return sprintf(buf, "{%pUl}\n", |
| 216 | hv_dev->channel->offermsg.offer.if_instance.b); |
| 217 | } |
| 218 | static DEVICE_ATTR_RO(device_id); |
| 219 | |
Greg Kroah-Hartman | 647fa37 | 2013-09-13 11:32:52 -0700 | [diff] [blame] | 220 | static ssize_t modalias_show(struct device *dev, |
| 221 | struct device_attribute *dev_attr, char *buf) |
| 222 | { |
| 223 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 224 | char alias_name[VMBUS_ALIAS_LEN + 1]; |
| 225 | |
| 226 | print_alias_name(hv_dev, alias_name); |
| 227 | return sprintf(buf, "vmbus:%s\n", alias_name); |
| 228 | } |
| 229 | static DEVICE_ATTR_RO(modalias); |
| 230 | |
Stephen Hemminger | 7ceb1c3 | 2018-07-28 21:58:48 +0000 | [diff] [blame] | 231 | #ifdef CONFIG_NUMA |
| 232 | static ssize_t numa_node_show(struct device *dev, |
| 233 | struct device_attribute *attr, char *buf) |
| 234 | { |
| 235 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 236 | |
| 237 | if (!hv_dev->channel) |
| 238 | return -ENODEV; |
| 239 | |
| 240 | return sprintf(buf, "%d\n", hv_dev->channel->numa_node); |
| 241 | } |
| 242 | static DEVICE_ATTR_RO(numa_node); |
| 243 | #endif |
| 244 | |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 245 | static ssize_t server_monitor_pending_show(struct device *dev, |
| 246 | struct device_attribute *dev_attr, |
| 247 | char *buf) |
| 248 | { |
| 249 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 250 | |
| 251 | if (!hv_dev->channel) |
| 252 | return -ENODEV; |
| 253 | return sprintf(buf, "%d\n", |
| 254 | channel_pending(hv_dev->channel, |
Kimberly Brown | fd8e3c3 | 2019-02-19 00:38:06 -0500 | [diff] [blame] | 255 | vmbus_connection.monitor_pages[0])); |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 256 | } |
| 257 | static DEVICE_ATTR_RO(server_monitor_pending); |
| 258 | |
| 259 | static ssize_t client_monitor_pending_show(struct device *dev, |
| 260 | struct device_attribute *dev_attr, |
| 261 | char *buf) |
| 262 | { |
| 263 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 264 | |
| 265 | if (!hv_dev->channel) |
| 266 | return -ENODEV; |
| 267 | return sprintf(buf, "%d\n", |
| 268 | channel_pending(hv_dev->channel, |
| 269 | vmbus_connection.monitor_pages[1])); |
| 270 | } |
| 271 | static DEVICE_ATTR_RO(client_monitor_pending); |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 272 | |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 273 | static ssize_t server_monitor_latency_show(struct device *dev, |
| 274 | struct device_attribute *dev_attr, |
| 275 | char *buf) |
| 276 | { |
| 277 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 278 | |
| 279 | if (!hv_dev->channel) |
| 280 | return -ENODEV; |
| 281 | return sprintf(buf, "%d\n", |
| 282 | channel_latency(hv_dev->channel, |
| 283 | vmbus_connection.monitor_pages[0])); |
| 284 | } |
| 285 | static DEVICE_ATTR_RO(server_monitor_latency); |
| 286 | |
| 287 | static ssize_t client_monitor_latency_show(struct device *dev, |
| 288 | struct device_attribute *dev_attr, |
| 289 | char *buf) |
| 290 | { |
| 291 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 292 | |
| 293 | if (!hv_dev->channel) |
| 294 | return -ENODEV; |
| 295 | return sprintf(buf, "%d\n", |
| 296 | channel_latency(hv_dev->channel, |
| 297 | vmbus_connection.monitor_pages[1])); |
| 298 | } |
| 299 | static DEVICE_ATTR_RO(client_monitor_latency); |
| 300 | |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 301 | static ssize_t server_monitor_conn_id_show(struct device *dev, |
| 302 | struct device_attribute *dev_attr, |
| 303 | char *buf) |
| 304 | { |
| 305 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 306 | |
| 307 | if (!hv_dev->channel) |
| 308 | return -ENODEV; |
| 309 | return sprintf(buf, "%d\n", |
| 310 | channel_conn_id(hv_dev->channel, |
| 311 | vmbus_connection.monitor_pages[0])); |
| 312 | } |
| 313 | static DEVICE_ATTR_RO(server_monitor_conn_id); |
| 314 | |
| 315 | static ssize_t client_monitor_conn_id_show(struct device *dev, |
| 316 | struct device_attribute *dev_attr, |
| 317 | char *buf) |
| 318 | { |
| 319 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 320 | |
| 321 | if (!hv_dev->channel) |
| 322 | return -ENODEV; |
| 323 | return sprintf(buf, "%d\n", |
| 324 | channel_conn_id(hv_dev->channel, |
| 325 | vmbus_connection.monitor_pages[1])); |
| 326 | } |
| 327 | static DEVICE_ATTR_RO(client_monitor_conn_id); |
| 328 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 329 | static ssize_t out_intr_mask_show(struct device *dev, |
| 330 | struct device_attribute *dev_attr, char *buf) |
| 331 | { |
| 332 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 333 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 334 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 335 | |
| 336 | if (!hv_dev->channel) |
| 337 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 338 | |
| 339 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 340 | &outbound); |
| 341 | if (ret < 0) |
| 342 | return ret; |
| 343 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 344 | return sprintf(buf, "%d\n", outbound.current_interrupt_mask); |
| 345 | } |
| 346 | static DEVICE_ATTR_RO(out_intr_mask); |
| 347 | |
| 348 | static ssize_t out_read_index_show(struct device *dev, |
| 349 | struct device_attribute *dev_attr, char *buf) |
| 350 | { |
| 351 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 352 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 353 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 354 | |
| 355 | if (!hv_dev->channel) |
| 356 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 357 | |
| 358 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 359 | &outbound); |
| 360 | if (ret < 0) |
| 361 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 362 | return sprintf(buf, "%d\n", outbound.current_read_index); |
| 363 | } |
| 364 | static DEVICE_ATTR_RO(out_read_index); |
| 365 | |
| 366 | static ssize_t out_write_index_show(struct device *dev, |
| 367 | struct device_attribute *dev_attr, |
| 368 | char *buf) |
| 369 | { |
| 370 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 371 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 372 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 373 | |
| 374 | if (!hv_dev->channel) |
| 375 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 376 | |
| 377 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 378 | &outbound); |
| 379 | if (ret < 0) |
| 380 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 381 | return sprintf(buf, "%d\n", outbound.current_write_index); |
| 382 | } |
| 383 | static DEVICE_ATTR_RO(out_write_index); |
| 384 | |
| 385 | static ssize_t out_read_bytes_avail_show(struct device *dev, |
| 386 | struct device_attribute *dev_attr, |
| 387 | char *buf) |
| 388 | { |
| 389 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 390 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 391 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 392 | |
| 393 | if (!hv_dev->channel) |
| 394 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 395 | |
| 396 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 397 | &outbound); |
| 398 | if (ret < 0) |
| 399 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 400 | return sprintf(buf, "%d\n", outbound.bytes_avail_toread); |
| 401 | } |
| 402 | static DEVICE_ATTR_RO(out_read_bytes_avail); |
| 403 | |
| 404 | static ssize_t out_write_bytes_avail_show(struct device *dev, |
| 405 | struct device_attribute *dev_attr, |
| 406 | char *buf) |
| 407 | { |
| 408 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 409 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 410 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 411 | |
| 412 | if (!hv_dev->channel) |
| 413 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 414 | |
| 415 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 416 | &outbound); |
| 417 | if (ret < 0) |
| 418 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 419 | return sprintf(buf, "%d\n", outbound.bytes_avail_towrite); |
| 420 | } |
| 421 | static DEVICE_ATTR_RO(out_write_bytes_avail); |
| 422 | |
| 423 | static ssize_t in_intr_mask_show(struct device *dev, |
| 424 | struct device_attribute *dev_attr, char *buf) |
| 425 | { |
| 426 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 427 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 428 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 429 | |
| 430 | if (!hv_dev->channel) |
| 431 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 432 | |
| 433 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 434 | if (ret < 0) |
| 435 | return ret; |
| 436 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 437 | return sprintf(buf, "%d\n", inbound.current_interrupt_mask); |
| 438 | } |
| 439 | static DEVICE_ATTR_RO(in_intr_mask); |
| 440 | |
| 441 | static ssize_t in_read_index_show(struct device *dev, |
| 442 | struct device_attribute *dev_attr, char *buf) |
| 443 | { |
| 444 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 445 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 446 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 447 | |
| 448 | if (!hv_dev->channel) |
| 449 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 450 | |
| 451 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 452 | if (ret < 0) |
| 453 | return ret; |
| 454 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 455 | return sprintf(buf, "%d\n", inbound.current_read_index); |
| 456 | } |
| 457 | static DEVICE_ATTR_RO(in_read_index); |
| 458 | |
| 459 | static ssize_t in_write_index_show(struct device *dev, |
| 460 | struct device_attribute *dev_attr, char *buf) |
| 461 | { |
| 462 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 463 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 464 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 465 | |
| 466 | if (!hv_dev->channel) |
| 467 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 468 | |
| 469 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 470 | if (ret < 0) |
| 471 | return ret; |
| 472 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 473 | return sprintf(buf, "%d\n", inbound.current_write_index); |
| 474 | } |
| 475 | static DEVICE_ATTR_RO(in_write_index); |
| 476 | |
| 477 | static ssize_t in_read_bytes_avail_show(struct device *dev, |
| 478 | struct device_attribute *dev_attr, |
| 479 | char *buf) |
| 480 | { |
| 481 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 482 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 483 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 484 | |
| 485 | if (!hv_dev->channel) |
| 486 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 487 | |
| 488 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 489 | if (ret < 0) |
| 490 | return ret; |
| 491 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 492 | return sprintf(buf, "%d\n", inbound.bytes_avail_toread); |
| 493 | } |
| 494 | static DEVICE_ATTR_RO(in_read_bytes_avail); |
| 495 | |
| 496 | static ssize_t in_write_bytes_avail_show(struct device *dev, |
| 497 | struct device_attribute *dev_attr, |
| 498 | char *buf) |
| 499 | { |
| 500 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 501 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 502 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 503 | |
| 504 | if (!hv_dev->channel) |
| 505 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 506 | |
| 507 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 508 | if (ret < 0) |
| 509 | return ret; |
| 510 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 511 | return sprintf(buf, "%d\n", inbound.bytes_avail_towrite); |
| 512 | } |
| 513 | static DEVICE_ATTR_RO(in_write_bytes_avail); |
| 514 | |
Dexuan Cui | 042ab03 | 2015-08-05 00:52:43 -0700 | [diff] [blame] | 515 | static ssize_t channel_vp_mapping_show(struct device *dev, |
| 516 | struct device_attribute *dev_attr, |
| 517 | char *buf) |
| 518 | { |
| 519 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 520 | struct vmbus_channel *channel = hv_dev->channel, *cur_sc; |
| 521 | unsigned long flags; |
| 522 | int buf_size = PAGE_SIZE, n_written, tot_written; |
| 523 | struct list_head *cur; |
| 524 | |
| 525 | if (!channel) |
| 526 | return -ENODEV; |
| 527 | |
| 528 | tot_written = snprintf(buf, buf_size, "%u:%u\n", |
| 529 | channel->offermsg.child_relid, channel->target_cpu); |
| 530 | |
| 531 | spin_lock_irqsave(&channel->lock, flags); |
| 532 | |
| 533 | list_for_each(cur, &channel->sc_list) { |
| 534 | if (tot_written >= buf_size - 1) |
| 535 | break; |
| 536 | |
| 537 | cur_sc = list_entry(cur, struct vmbus_channel, sc_list); |
| 538 | n_written = scnprintf(buf + tot_written, |
| 539 | buf_size - tot_written, |
| 540 | "%u:%u\n", |
| 541 | cur_sc->offermsg.child_relid, |
| 542 | cur_sc->target_cpu); |
| 543 | tot_written += n_written; |
| 544 | } |
| 545 | |
| 546 | spin_unlock_irqrestore(&channel->lock, flags); |
| 547 | |
| 548 | return tot_written; |
| 549 | } |
| 550 | static DEVICE_ATTR_RO(channel_vp_mapping); |
| 551 | |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 552 | static ssize_t vendor_show(struct device *dev, |
| 553 | struct device_attribute *dev_attr, |
| 554 | char *buf) |
| 555 | { |
| 556 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 557 | return sprintf(buf, "0x%x\n", hv_dev->vendor_id); |
| 558 | } |
| 559 | static DEVICE_ATTR_RO(vendor); |
| 560 | |
| 561 | static ssize_t device_show(struct device *dev, |
| 562 | struct device_attribute *dev_attr, |
| 563 | char *buf) |
| 564 | { |
| 565 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 566 | return sprintf(buf, "0x%x\n", hv_dev->device_id); |
| 567 | } |
| 568 | static DEVICE_ATTR_RO(device); |
| 569 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 570 | static ssize_t driver_override_store(struct device *dev, |
| 571 | struct device_attribute *attr, |
| 572 | const char *buf, size_t count) |
| 573 | { |
| 574 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 575 | char *driver_override, *old, *cp; |
| 576 | |
| 577 | /* We need to keep extra room for a newline */ |
| 578 | if (count >= (PAGE_SIZE - 1)) |
| 579 | return -EINVAL; |
| 580 | |
| 581 | driver_override = kstrndup(buf, count, GFP_KERNEL); |
| 582 | if (!driver_override) |
| 583 | return -ENOMEM; |
| 584 | |
| 585 | cp = strchr(driver_override, '\n'); |
| 586 | if (cp) |
| 587 | *cp = '\0'; |
| 588 | |
| 589 | device_lock(dev); |
| 590 | old = hv_dev->driver_override; |
| 591 | if (strlen(driver_override)) { |
| 592 | hv_dev->driver_override = driver_override; |
| 593 | } else { |
| 594 | kfree(driver_override); |
| 595 | hv_dev->driver_override = NULL; |
| 596 | } |
| 597 | device_unlock(dev); |
| 598 | |
| 599 | kfree(old); |
| 600 | |
| 601 | return count; |
| 602 | } |
| 603 | |
| 604 | static ssize_t driver_override_show(struct device *dev, |
| 605 | struct device_attribute *attr, char *buf) |
| 606 | { |
| 607 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 608 | ssize_t len; |
| 609 | |
| 610 | device_lock(dev); |
| 611 | len = snprintf(buf, PAGE_SIZE, "%s\n", hv_dev->driver_override); |
| 612 | device_unlock(dev); |
| 613 | |
| 614 | return len; |
| 615 | } |
| 616 | static DEVICE_ATTR_RW(driver_override); |
| 617 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 618 | /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */ |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 619 | static struct attribute *vmbus_dev_attrs[] = { |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 620 | &dev_attr_id.attr, |
Greg Kroah-Hartman | a8fb5f3 | 2013-09-13 11:32:50 -0700 | [diff] [blame] | 621 | &dev_attr_state.attr, |
Greg Kroah-Hartman | 5ffd00e | 2013-09-13 11:32:51 -0700 | [diff] [blame] | 622 | &dev_attr_monitor_id.attr, |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 623 | &dev_attr_class_id.attr, |
Greg Kroah-Hartman | 7c55e1d | 2013-09-13 11:32:54 -0700 | [diff] [blame] | 624 | &dev_attr_device_id.attr, |
Greg Kroah-Hartman | 647fa37 | 2013-09-13 11:32:52 -0700 | [diff] [blame] | 625 | &dev_attr_modalias.attr, |
Stephen Hemminger | 7ceb1c3 | 2018-07-28 21:58:48 +0000 | [diff] [blame] | 626 | #ifdef CONFIG_NUMA |
| 627 | &dev_attr_numa_node.attr, |
| 628 | #endif |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 629 | &dev_attr_server_monitor_pending.attr, |
| 630 | &dev_attr_client_monitor_pending.attr, |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 631 | &dev_attr_server_monitor_latency.attr, |
| 632 | &dev_attr_client_monitor_latency.attr, |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 633 | &dev_attr_server_monitor_conn_id.attr, |
| 634 | &dev_attr_client_monitor_conn_id.attr, |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 635 | &dev_attr_out_intr_mask.attr, |
| 636 | &dev_attr_out_read_index.attr, |
| 637 | &dev_attr_out_write_index.attr, |
| 638 | &dev_attr_out_read_bytes_avail.attr, |
| 639 | &dev_attr_out_write_bytes_avail.attr, |
| 640 | &dev_attr_in_intr_mask.attr, |
| 641 | &dev_attr_in_read_index.attr, |
| 642 | &dev_attr_in_write_index.attr, |
| 643 | &dev_attr_in_read_bytes_avail.attr, |
| 644 | &dev_attr_in_write_bytes_avail.attr, |
Dexuan Cui | 042ab03 | 2015-08-05 00:52:43 -0700 | [diff] [blame] | 645 | &dev_attr_channel_vp_mapping.attr, |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 646 | &dev_attr_vendor.attr, |
| 647 | &dev_attr_device.attr, |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 648 | &dev_attr_driver_override.attr, |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 649 | NULL, |
| 650 | }; |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 651 | |
| 652 | /* |
| 653 | * Device-level attribute_group callback function. Returns the permission for |
| 654 | * each attribute, and returns 0 if an attribute is not visible. |
| 655 | */ |
| 656 | static umode_t vmbus_dev_attr_is_visible(struct kobject *kobj, |
| 657 | struct attribute *attr, int idx) |
| 658 | { |
| 659 | struct device *dev = kobj_to_dev(kobj); |
| 660 | const struct hv_device *hv_dev = device_to_hv_device(dev); |
| 661 | |
| 662 | /* Hide the monitor attributes if the monitor mechanism is not used. */ |
| 663 | if (!hv_dev->channel->offermsg.monitor_allocated && |
| 664 | (attr == &dev_attr_monitor_id.attr || |
| 665 | attr == &dev_attr_server_monitor_pending.attr || |
| 666 | attr == &dev_attr_client_monitor_pending.attr || |
| 667 | attr == &dev_attr_server_monitor_latency.attr || |
| 668 | attr == &dev_attr_client_monitor_latency.attr || |
| 669 | attr == &dev_attr_server_monitor_conn_id.attr || |
| 670 | attr == &dev_attr_client_monitor_conn_id.attr)) |
| 671 | return 0; |
| 672 | |
| 673 | return attr->mode; |
| 674 | } |
| 675 | |
| 676 | static const struct attribute_group vmbus_dev_group = { |
| 677 | .attrs = vmbus_dev_attrs, |
| 678 | .is_visible = vmbus_dev_attr_is_visible |
| 679 | }; |
| 680 | __ATTRIBUTE_GROUPS(vmbus_dev); |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 681 | |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 682 | /* |
| 683 | * vmbus_uevent - add uevent for our device |
| 684 | * |
| 685 | * This routine is invoked when a device is added or removed on the vmbus to |
| 686 | * generate a uevent to udev in the userspace. The udev will then look at its |
| 687 | * rule and the uevent generated here to load the appropriate driver |
K. Y. Srinivasan | 0ddda66 | 2011-08-25 09:48:38 -0700 | [diff] [blame] | 688 | * |
| 689 | * The alias string will be of the form vmbus:guid where guid is the string |
| 690 | * representation of the device guid (each byte of the guid will be |
| 691 | * represented with two hex characters. |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 692 | */ |
| 693 | static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) |
| 694 | { |
| 695 | struct hv_device *dev = device_to_hv_device(device); |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 696 | int ret; |
| 697 | char alias_name[VMBUS_ALIAS_LEN + 1]; |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 698 | |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 699 | print_alias_name(dev, alias_name); |
K. Y. Srinivasan | 0ddda66 | 2011-08-25 09:48:38 -0700 | [diff] [blame] | 700 | ret = add_uevent_var(env, "MODALIAS=vmbus:%s", alias_name); |
| 701 | return ret; |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 704 | static const struct hv_vmbus_device_id * |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 705 | hv_vmbus_dev_match(const struct hv_vmbus_device_id *id, const guid_t *guid) |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 706 | { |
| 707 | if (id == NULL) |
| 708 | return NULL; /* empty device table */ |
| 709 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 710 | for (; !guid_is_null(&id->guid); id++) |
| 711 | if (guid_equal(&id->guid, guid)) |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 712 | return id; |
| 713 | |
| 714 | return NULL; |
| 715 | } |
| 716 | |
| 717 | static const struct hv_vmbus_device_id * |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 718 | hv_vmbus_dynid_match(struct hv_driver *drv, const guid_t *guid) |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 719 | { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 720 | const struct hv_vmbus_device_id *id = NULL; |
| 721 | struct vmbus_dynid *dynid; |
| 722 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 723 | spin_lock(&drv->dynids.lock); |
| 724 | list_for_each_entry(dynid, &drv->dynids.list, node) { |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 725 | if (guid_equal(&dynid->id.guid, guid)) { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 726 | id = &dynid->id; |
| 727 | break; |
| 728 | } |
| 729 | } |
| 730 | spin_unlock(&drv->dynids.lock); |
| 731 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 732 | return id; |
| 733 | } |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 734 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 735 | static const struct hv_vmbus_device_id vmbus_device_null; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 736 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 737 | /* |
| 738 | * Return a matching hv_vmbus_device_id pointer. |
| 739 | * If there is no match, return NULL. |
| 740 | */ |
| 741 | static const struct hv_vmbus_device_id *hv_vmbus_get_id(struct hv_driver *drv, |
| 742 | struct hv_device *dev) |
| 743 | { |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 744 | const guid_t *guid = &dev->dev_type; |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 745 | const struct hv_vmbus_device_id *id; |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 746 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 747 | /* When driver_override is set, only bind to the matching driver */ |
| 748 | if (dev->driver_override && strcmp(dev->driver_override, drv->name)) |
| 749 | return NULL; |
| 750 | |
| 751 | /* Look at the dynamic ids first, before the static ones */ |
| 752 | id = hv_vmbus_dynid_match(drv, guid); |
| 753 | if (!id) |
| 754 | id = hv_vmbus_dev_match(drv->id_table, guid); |
| 755 | |
| 756 | /* driver_override will always match, send a dummy id */ |
| 757 | if (!id && dev->driver_override) |
| 758 | id = &vmbus_device_null; |
| 759 | |
| 760 | return id; |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 763 | /* vmbus_add_dynid - add a new device ID to this driver and re-probe devices */ |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 764 | static int vmbus_add_dynid(struct hv_driver *drv, guid_t *guid) |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 765 | { |
| 766 | struct vmbus_dynid *dynid; |
| 767 | |
| 768 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); |
| 769 | if (!dynid) |
| 770 | return -ENOMEM; |
| 771 | |
| 772 | dynid->id.guid = *guid; |
| 773 | |
| 774 | spin_lock(&drv->dynids.lock); |
| 775 | list_add_tail(&dynid->node, &drv->dynids.list); |
| 776 | spin_unlock(&drv->dynids.lock); |
| 777 | |
| 778 | return driver_attach(&drv->driver); |
| 779 | } |
| 780 | |
| 781 | static void vmbus_free_dynids(struct hv_driver *drv) |
| 782 | { |
| 783 | struct vmbus_dynid *dynid, *n; |
| 784 | |
| 785 | spin_lock(&drv->dynids.lock); |
| 786 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
| 787 | list_del(&dynid->node); |
| 788 | kfree(dynid); |
| 789 | } |
| 790 | spin_unlock(&drv->dynids.lock); |
| 791 | } |
| 792 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 793 | /* |
| 794 | * store_new_id - sysfs frontend to vmbus_add_dynid() |
| 795 | * |
| 796 | * Allow GUIDs to be added to an existing driver via sysfs. |
| 797 | */ |
| 798 | static ssize_t new_id_store(struct device_driver *driver, const char *buf, |
| 799 | size_t count) |
| 800 | { |
| 801 | struct hv_driver *drv = drv_to_hv_drv(driver); |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 802 | guid_t guid; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 803 | ssize_t retval; |
| 804 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 805 | retval = guid_parse(buf, &guid); |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 806 | if (retval) |
| 807 | return retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 808 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 809 | if (hv_vmbus_dynid_match(drv, &guid)) |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 810 | return -EEXIST; |
| 811 | |
| 812 | retval = vmbus_add_dynid(drv, &guid); |
| 813 | if (retval) |
| 814 | return retval; |
| 815 | return count; |
| 816 | } |
| 817 | static DRIVER_ATTR_WO(new_id); |
| 818 | |
| 819 | /* |
| 820 | * store_remove_id - remove a PCI device ID from this driver |
| 821 | * |
| 822 | * Removes a dynamic pci device ID to this driver. |
| 823 | */ |
| 824 | static ssize_t remove_id_store(struct device_driver *driver, const char *buf, |
| 825 | size_t count) |
| 826 | { |
| 827 | struct hv_driver *drv = drv_to_hv_drv(driver); |
| 828 | struct vmbus_dynid *dynid, *n; |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 829 | guid_t guid; |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 830 | ssize_t retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 831 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 832 | retval = guid_parse(buf, &guid); |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 833 | if (retval) |
| 834 | return retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 835 | |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 836 | retval = -ENODEV; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 837 | spin_lock(&drv->dynids.lock); |
| 838 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
| 839 | struct hv_vmbus_device_id *id = &dynid->id; |
| 840 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 841 | if (guid_equal(&id->guid, &guid)) { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 842 | list_del(&dynid->node); |
| 843 | kfree(dynid); |
| 844 | retval = count; |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | spin_unlock(&drv->dynids.lock); |
| 849 | |
| 850 | return retval; |
| 851 | } |
| 852 | static DRIVER_ATTR_WO(remove_id); |
| 853 | |
| 854 | static struct attribute *vmbus_drv_attrs[] = { |
| 855 | &driver_attr_new_id.attr, |
| 856 | &driver_attr_remove_id.attr, |
| 857 | NULL, |
| 858 | }; |
| 859 | ATTRIBUTE_GROUPS(vmbus_drv); |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 860 | |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 861 | |
| 862 | /* |
| 863 | * vmbus_match - Attempt to match the specified device to the specified driver |
| 864 | */ |
| 865 | static int vmbus_match(struct device *device, struct device_driver *driver) |
| 866 | { |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 867 | struct hv_driver *drv = drv_to_hv_drv(driver); |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 868 | struct hv_device *hv_dev = device_to_hv_device(device); |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 869 | |
Dexuan Cui | 8981da3 | 2016-01-27 22:29:41 -0800 | [diff] [blame] | 870 | /* The hv_sock driver handles all hv_sock offers. */ |
| 871 | if (is_hvsock_channel(hv_dev->channel)) |
| 872 | return drv->hvsock; |
| 873 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 874 | if (hv_vmbus_get_id(drv, hv_dev)) |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 875 | return 1; |
K. Y. Srinivasan | de632a2b | 2011-04-26 09:20:24 -0700 | [diff] [blame] | 876 | |
K. Y. Srinivasan | 5841a82 | 2011-08-25 09:48:39 -0700 | [diff] [blame] | 877 | return 0; |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 878 | } |
| 879 | |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 880 | /* |
| 881 | * vmbus_probe - Add the new vmbus's child device |
| 882 | */ |
| 883 | static int vmbus_probe(struct device *child_device) |
| 884 | { |
| 885 | int ret = 0; |
| 886 | struct hv_driver *drv = |
| 887 | drv_to_hv_drv(child_device->driver); |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 888 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 889 | const struct hv_vmbus_device_id *dev_id; |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 890 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 891 | dev_id = hv_vmbus_get_id(drv, dev); |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 892 | if (drv->probe) { |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 893 | ret = drv->probe(dev, dev_id); |
K. Y. Srinivasan | b14a7b3 | 2011-04-29 13:45:03 -0700 | [diff] [blame] | 894 | if (ret != 0) |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 895 | pr_err("probe failed for device %s (%d)\n", |
| 896 | dev_name(child_device), ret); |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 897 | |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 898 | } else { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 899 | pr_err("probe not set for driver %s\n", |
| 900 | dev_name(child_device)); |
K. Y. Srinivasan | 6de925b | 2011-06-06 15:50:07 -0700 | [diff] [blame] | 901 | ret = -ENODEV; |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 902 | } |
| 903 | return ret; |
| 904 | } |
| 905 | |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 906 | /* |
| 907 | * vmbus_remove - Remove a vmbus device |
| 908 | */ |
| 909 | static int vmbus_remove(struct device *child_device) |
| 910 | { |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 911 | struct hv_driver *drv; |
K. Y. Srinivasan | 415b023 | 2011-04-29 13:45:12 -0700 | [diff] [blame] | 912 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 913 | |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 914 | if (child_device->driver) { |
| 915 | drv = drv_to_hv_drv(child_device->driver); |
| 916 | if (drv->remove) |
| 917 | drv->remove(dev); |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 918 | } |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 919 | |
| 920 | return 0; |
| 921 | } |
| 922 | |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 923 | |
| 924 | /* |
| 925 | * vmbus_shutdown - Shutdown a vmbus device |
| 926 | */ |
| 927 | static void vmbus_shutdown(struct device *child_device) |
| 928 | { |
| 929 | struct hv_driver *drv; |
K. Y. Srinivasan | ca6887f | 2011-04-29 13:45:14 -0700 | [diff] [blame] | 930 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 931 | |
| 932 | |
| 933 | /* The device may not be attached yet */ |
| 934 | if (!child_device->driver) |
| 935 | return; |
| 936 | |
| 937 | drv = drv_to_hv_drv(child_device->driver); |
| 938 | |
K. Y. Srinivasan | ca6887f | 2011-04-29 13:45:14 -0700 | [diff] [blame] | 939 | if (drv->shutdown) |
| 940 | drv->shutdown(dev); |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Dexuan Cui | 83b50f8 | 2019-09-19 21:46:12 +0000 | [diff] [blame] | 943 | #ifdef CONFIG_PM_SLEEP |
Dexuan Cui | 271b222 | 2019-09-05 23:01:17 +0000 | [diff] [blame] | 944 | /* |
| 945 | * vmbus_suspend - Suspend a vmbus device |
| 946 | */ |
| 947 | static int vmbus_suspend(struct device *child_device) |
| 948 | { |
| 949 | struct hv_driver *drv; |
| 950 | struct hv_device *dev = device_to_hv_device(child_device); |
| 951 | |
| 952 | /* The device may not be attached yet */ |
| 953 | if (!child_device->driver) |
| 954 | return 0; |
| 955 | |
| 956 | drv = drv_to_hv_drv(child_device->driver); |
| 957 | if (!drv->suspend) |
| 958 | return -EOPNOTSUPP; |
| 959 | |
| 960 | return drv->suspend(dev); |
| 961 | } |
| 962 | |
| 963 | /* |
| 964 | * vmbus_resume - Resume a vmbus device |
| 965 | */ |
| 966 | static int vmbus_resume(struct device *child_device) |
| 967 | { |
| 968 | struct hv_driver *drv; |
| 969 | struct hv_device *dev = device_to_hv_device(child_device); |
| 970 | |
| 971 | /* The device may not be attached yet */ |
| 972 | if (!child_device->driver) |
| 973 | return 0; |
| 974 | |
| 975 | drv = drv_to_hv_drv(child_device->driver); |
| 976 | if (!drv->resume) |
| 977 | return -EOPNOTSUPP; |
| 978 | |
| 979 | return drv->resume(dev); |
| 980 | } |
Dexuan Cui | 83b50f8 | 2019-09-19 21:46:12 +0000 | [diff] [blame] | 981 | #endif /* CONFIG_PM_SLEEP */ |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 982 | |
| 983 | /* |
| 984 | * vmbus_device_release - Final callback release of the vmbus child device |
| 985 | */ |
| 986 | static void vmbus_device_release(struct device *device) |
| 987 | { |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 988 | struct hv_device *hv_dev = device_to_hv_device(device); |
Dexuan Cui | 34c6801 | 2015-12-14 16:01:49 -0800 | [diff] [blame] | 989 | struct vmbus_channel *channel = hv_dev->channel; |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 990 | |
Branden Bonaby | af9ca6f | 2019-10-03 17:01:49 -0400 | [diff] [blame] | 991 | hv_debug_rm_dev_dir(hv_dev); |
| 992 | |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 993 | mutex_lock(&vmbus_connection.channel_mutex); |
Stephen Hemminger | 800b932 | 2018-09-14 09:10:15 -0700 | [diff] [blame] | 994 | hv_process_channel_removal(channel); |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 995 | mutex_unlock(&vmbus_connection.channel_mutex); |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 996 | kfree(hv_dev); |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Dexuan Cui | 271b222 | 2019-09-05 23:01:17 +0000 | [diff] [blame] | 999 | /* |
| 1000 | * Note: we must use SET_NOIRQ_SYSTEM_SLEEP_PM_OPS rather than |
| 1001 | * SET_SYSTEM_SLEEP_PM_OPS: see the comment before vmbus_bus_pm. |
| 1002 | */ |
| 1003 | static const struct dev_pm_ops vmbus_pm = { |
| 1004 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(vmbus_suspend, vmbus_resume) |
| 1005 | }; |
| 1006 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1007 | /* The one and only one */ |
K. Y. Srinivasan | 9adcac5 | 2011-04-29 13:45:08 -0700 | [diff] [blame] | 1008 | static struct bus_type hv_bus = { |
| 1009 | .name = "vmbus", |
| 1010 | .match = vmbus_match, |
| 1011 | .shutdown = vmbus_shutdown, |
| 1012 | .remove = vmbus_remove, |
| 1013 | .probe = vmbus_probe, |
| 1014 | .uevent = vmbus_uevent, |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1015 | .dev_groups = vmbus_dev_groups, |
| 1016 | .drv_groups = vmbus_drv_groups, |
Dexuan Cui | 271b222 | 2019-09-05 23:01:17 +0000 | [diff] [blame] | 1017 | .pm = &vmbus_pm, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1018 | }; |
| 1019 | |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 1020 | struct onmessage_work_context { |
| 1021 | struct work_struct work; |
Vitaly Kuznetsov | a276463 | 2020-04-06 12:41:51 +0200 | [diff] [blame] | 1022 | struct { |
| 1023 | struct hv_message_header header; |
| 1024 | u8 payload[]; |
| 1025 | } msg; |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 1026 | }; |
| 1027 | |
| 1028 | static void vmbus_onmessage_work(struct work_struct *work) |
| 1029 | { |
| 1030 | struct onmessage_work_context *ctx; |
| 1031 | |
Vitaly Kuznetsov | 09a1962 | 2015-02-27 11:25:54 -0800 | [diff] [blame] | 1032 | /* Do not process messages if we're in DISCONNECTED state */ |
| 1033 | if (vmbus_connection.conn_state == DISCONNECTED) |
| 1034 | return; |
| 1035 | |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 1036 | ctx = container_of(work, struct onmessage_work_context, |
| 1037 | work); |
Vitaly Kuznetsov | 5cc4150 | 2020-04-06 12:41:52 +0200 | [diff] [blame] | 1038 | vmbus_onmessage((struct vmbus_channel_message_header *) |
| 1039 | &ctx->msg.payload); |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 1040 | kfree(ctx); |
| 1041 | } |
| 1042 | |
K. Y. Srinivasan | d81274a | 2016-02-26 15:13:21 -0800 | [diff] [blame] | 1043 | void vmbus_on_msg_dpc(unsigned long data) |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1044 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1045 | struct hv_per_cpu_context *hv_cpu = (void *)data; |
| 1046 | void *page_addr = hv_cpu->synic_message_page; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1047 | struct hv_message *msg = (struct hv_message *)page_addr + |
| 1048 | VMBUS_MESSAGE_SINT; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1049 | struct vmbus_channel_message_header *hdr; |
Stephen Hemminger | e6242fa | 2017-03-04 18:27:16 -0700 | [diff] [blame] | 1050 | const struct vmbus_channel_message_table_entry *entry; |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 1051 | struct onmessage_work_context *ctx; |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 1052 | u32 message_type = msg->header.message_type; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1053 | |
Vitaly Kuznetsov | b0a284d | 2020-04-06 12:43:15 +0200 | [diff] [blame] | 1054 | /* |
| 1055 | * 'enum vmbus_channel_message_type' is supposed to always be 'u32' as |
| 1056 | * it is being used in 'struct vmbus_channel_message_header' definition |
| 1057 | * which is supposed to match hypervisor ABI. |
| 1058 | */ |
| 1059 | BUILD_BUG_ON(sizeof(enum vmbus_channel_message_type) != sizeof(u32)); |
| 1060 | |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 1061 | if (message_type == HVMSG_NONE) |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1062 | /* no msg */ |
| 1063 | return; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1064 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1065 | hdr = (struct vmbus_channel_message_header *)msg->u.payload; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1066 | |
Vitaly Kuznetsov | c9fe0f8 | 2017-10-29 12:21:00 -0700 | [diff] [blame] | 1067 | trace_vmbus_on_msg_dpc(hdr); |
| 1068 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1069 | if (hdr->msgtype >= CHANNELMSG_COUNT) { |
| 1070 | WARN_ONCE(1, "unknown msgtype=%d\n", hdr->msgtype); |
| 1071 | goto msg_handled; |
| 1072 | } |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1073 | |
Vitaly Kuznetsov | ac0f7d42 | 2020-04-06 12:41:50 +0200 | [diff] [blame] | 1074 | if (msg->header.payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT) { |
| 1075 | WARN_ONCE(1, "payload size is too large (%d)\n", |
| 1076 | msg->header.payload_size); |
| 1077 | goto msg_handled; |
| 1078 | } |
| 1079 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1080 | entry = &channel_message_table[hdr->msgtype]; |
Dexuan Cui | ddc9d35 | 2020-01-19 15:29:22 -0800 | [diff] [blame] | 1081 | |
| 1082 | if (!entry->message_handler) |
| 1083 | goto msg_handled; |
| 1084 | |
Vitaly Kuznetsov | 52c7803 | 2020-04-06 12:43:26 +0200 | [diff] [blame^] | 1085 | if (msg->header.payload_size < entry->min_payload_len) { |
| 1086 | WARN_ONCE(1, "message too short: msgtype=%d len=%d\n", |
| 1087 | hdr->msgtype, msg->header.payload_size); |
| 1088 | goto msg_handled; |
| 1089 | } |
| 1090 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1091 | if (entry->handler_type == VMHT_BLOCKING) { |
Vitaly Kuznetsov | a276463 | 2020-04-06 12:41:51 +0200 | [diff] [blame] | 1092 | ctx = kmalloc(sizeof(*ctx) + msg->header.payload_size, |
| 1093 | GFP_ATOMIC); |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1094 | if (ctx == NULL) |
| 1095 | return; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1096 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1097 | INIT_WORK(&ctx->work, vmbus_onmessage_work); |
Vitaly Kuznetsov | ac0f7d42 | 2020-04-06 12:41:50 +0200 | [diff] [blame] | 1098 | memcpy(&ctx->msg, msg, sizeof(msg->header) + |
| 1099 | msg->header.payload_size); |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1100 | |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 1101 | /* |
| 1102 | * The host can generate a rescind message while we |
| 1103 | * may still be handling the original offer. We deal with |
| 1104 | * this condition by ensuring the processing is done on the |
| 1105 | * same CPU. |
| 1106 | */ |
| 1107 | switch (hdr->msgtype) { |
| 1108 | case CHANNELMSG_RESCIND_CHANNELOFFER: |
| 1109 | /* |
| 1110 | * If we are handling the rescind message; |
| 1111 | * schedule the work on the global work queue. |
| 1112 | */ |
| 1113 | schedule_work_on(vmbus_connection.connect_cpu, |
| 1114 | &ctx->work); |
| 1115 | break; |
| 1116 | |
| 1117 | case CHANNELMSG_OFFERCHANNEL: |
| 1118 | atomic_inc(&vmbus_connection.offer_in_progress); |
| 1119 | queue_work_on(vmbus_connection.connect_cpu, |
| 1120 | vmbus_connection.work_queue, |
| 1121 | &ctx->work); |
| 1122 | break; |
| 1123 | |
| 1124 | default: |
| 1125 | queue_work(vmbus_connection.work_queue, &ctx->work); |
| 1126 | } |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1127 | } else |
| 1128 | entry->message_handler(hdr); |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1129 | |
| 1130 | msg_handled: |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 1131 | vmbus_signal_eom(msg, message_type); |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
Dexuan Cui | 83b50f8 | 2019-09-19 21:46:12 +0000 | [diff] [blame] | 1134 | #ifdef CONFIG_PM_SLEEP |
Dexuan Cui | 1f48dcf | 2019-09-05 23:01:20 +0000 | [diff] [blame] | 1135 | /* |
| 1136 | * Fake RESCIND_CHANNEL messages to clean up hv_sock channels by force for |
| 1137 | * hibernation, because hv_sock connections can not persist across hibernation. |
| 1138 | */ |
| 1139 | static void vmbus_force_channel_rescinded(struct vmbus_channel *channel) |
| 1140 | { |
| 1141 | struct onmessage_work_context *ctx; |
| 1142 | struct vmbus_channel_rescind_offer *rescind; |
| 1143 | |
| 1144 | WARN_ON(!is_hvsock_channel(channel)); |
| 1145 | |
| 1146 | /* |
Vitaly Kuznetsov | a276463 | 2020-04-06 12:41:51 +0200 | [diff] [blame] | 1147 | * Allocation size is small and the allocation should really not fail, |
Dexuan Cui | 1f48dcf | 2019-09-05 23:01:20 +0000 | [diff] [blame] | 1148 | * otherwise the state of the hv_sock connections ends up in limbo. |
| 1149 | */ |
Vitaly Kuznetsov | a276463 | 2020-04-06 12:41:51 +0200 | [diff] [blame] | 1150 | ctx = kzalloc(sizeof(*ctx) + sizeof(*rescind), |
| 1151 | GFP_KERNEL | __GFP_NOFAIL); |
Dexuan Cui | 1f48dcf | 2019-09-05 23:01:20 +0000 | [diff] [blame] | 1152 | |
| 1153 | /* |
| 1154 | * So far, these are not really used by Linux. Just set them to the |
| 1155 | * reasonable values conforming to the definitions of the fields. |
| 1156 | */ |
| 1157 | ctx->msg.header.message_type = 1; |
| 1158 | ctx->msg.header.payload_size = sizeof(*rescind); |
| 1159 | |
| 1160 | /* These values are actually used by Linux. */ |
Vitaly Kuznetsov | a276463 | 2020-04-06 12:41:51 +0200 | [diff] [blame] | 1161 | rescind = (struct vmbus_channel_rescind_offer *)ctx->msg.payload; |
Dexuan Cui | 1f48dcf | 2019-09-05 23:01:20 +0000 | [diff] [blame] | 1162 | rescind->header.msgtype = CHANNELMSG_RESCIND_CHANNELOFFER; |
| 1163 | rescind->child_relid = channel->offermsg.child_relid; |
| 1164 | |
| 1165 | INIT_WORK(&ctx->work, vmbus_onmessage_work); |
| 1166 | |
| 1167 | queue_work_on(vmbus_connection.connect_cpu, |
| 1168 | vmbus_connection.work_queue, |
| 1169 | &ctx->work); |
| 1170 | } |
Dexuan Cui | 83b50f8 | 2019-09-19 21:46:12 +0000 | [diff] [blame] | 1171 | #endif /* CONFIG_PM_SLEEP */ |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1172 | |
| 1173 | /* |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1174 | * Direct callback for channels using other deferred processing |
| 1175 | */ |
| 1176 | static void vmbus_channel_isr(struct vmbus_channel *channel) |
| 1177 | { |
| 1178 | void (*callback_fn)(void *); |
| 1179 | |
| 1180 | callback_fn = READ_ONCE(channel->onchannel_callback); |
| 1181 | if (likely(callback_fn != NULL)) |
| 1182 | (*callback_fn)(channel->channel_callback_context); |
| 1183 | } |
| 1184 | |
| 1185 | /* |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1186 | * Schedule all channels with events pending |
| 1187 | */ |
| 1188 | static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) |
| 1189 | { |
| 1190 | unsigned long *recv_int_page; |
| 1191 | u32 maxbits, relid; |
| 1192 | |
| 1193 | if (vmbus_proto_version < VERSION_WIN8) { |
| 1194 | maxbits = MAX_NUM_CHANNELS_SUPPORTED; |
| 1195 | recv_int_page = vmbus_connection.recv_int_page; |
| 1196 | } else { |
| 1197 | /* |
| 1198 | * When the host is win8 and beyond, the event page |
| 1199 | * can be directly checked to get the id of the channel |
| 1200 | * that has the interrupt pending. |
| 1201 | */ |
| 1202 | void *page_addr = hv_cpu->synic_event_page; |
| 1203 | union hv_synic_event_flags *event |
| 1204 | = (union hv_synic_event_flags *)page_addr + |
| 1205 | VMBUS_MESSAGE_SINT; |
| 1206 | |
| 1207 | maxbits = HV_EVENT_FLAGS_COUNT; |
| 1208 | recv_int_page = event->flags; |
| 1209 | } |
| 1210 | |
| 1211 | if (unlikely(!recv_int_page)) |
| 1212 | return; |
| 1213 | |
| 1214 | for_each_set_bit(relid, recv_int_page, maxbits) { |
| 1215 | struct vmbus_channel *channel; |
| 1216 | |
| 1217 | if (!sync_test_and_clear_bit(relid, recv_int_page)) |
| 1218 | continue; |
| 1219 | |
| 1220 | /* Special case - vmbus channel protocol msg */ |
| 1221 | if (relid == 0) |
| 1222 | continue; |
| 1223 | |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1224 | rcu_read_lock(); |
| 1225 | |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1226 | /* Find channel based on relid */ |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1227 | list_for_each_entry_rcu(channel, &hv_cpu->chan_list, percpu_list) { |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1228 | if (channel->offermsg.child_relid != relid) |
| 1229 | continue; |
| 1230 | |
K. Y. Srinivasan | 6f3d791 | 2017-08-11 10:03:59 -0700 | [diff] [blame] | 1231 | if (channel->rescind) |
| 1232 | continue; |
| 1233 | |
Vitaly Kuznetsov | 991f8f1 | 2017-10-29 12:21:16 -0700 | [diff] [blame] | 1234 | trace_vmbus_chan_sched(channel); |
| 1235 | |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1236 | ++channel->interrupts; |
| 1237 | |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1238 | switch (channel->callback_mode) { |
| 1239 | case HV_CALL_ISR: |
| 1240 | vmbus_channel_isr(channel); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1241 | break; |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1242 | |
| 1243 | case HV_CALL_BATCHED: |
| 1244 | hv_begin_read(&channel->inbound); |
| 1245 | /* fallthrough */ |
| 1246 | case HV_CALL_DIRECT: |
| 1247 | tasklet_schedule(&channel->callback_event); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1248 | } |
| 1249 | } |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1250 | |
| 1251 | rcu_read_unlock(); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1252 | } |
| 1253 | } |
| 1254 | |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1255 | static void vmbus_isr(void) |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1256 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1257 | struct hv_per_cpu_context *hv_cpu |
| 1258 | = this_cpu_ptr(hv_context.cpu_context); |
| 1259 | void *page_addr = hv_cpu->synic_event_page; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1260 | struct hv_message *msg; |
| 1261 | union hv_synic_event_flags *event; |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1262 | bool handled = false; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1263 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1264 | if (unlikely(page_addr == NULL)) |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1265 | return; |
K. Y. Srinivasan | 5ab0595 | 2012-12-01 06:46:55 -0800 | [diff] [blame] | 1266 | |
| 1267 | event = (union hv_synic_event_flags *)page_addr + |
| 1268 | VMBUS_MESSAGE_SINT; |
K. Y. Srinivasan | 7341d90 | 2011-08-31 14:35:56 -0700 | [diff] [blame] | 1269 | /* |
| 1270 | * Check for events before checking for messages. This is the order |
| 1271 | * in which events and messages are checked in Windows guests on |
| 1272 | * Hyper-V, and the Windows team suggested we do the same. |
| 1273 | */ |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1274 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1275 | if ((vmbus_proto_version == VERSION_WS2008) || |
| 1276 | (vmbus_proto_version == VERSION_WIN7)) { |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1277 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1278 | /* Since we are a child, we only need to check bit 0 */ |
Stephen Hemminger | 5c1bec6 | 2017-02-05 17:20:31 -0700 | [diff] [blame] | 1279 | if (sync_test_and_clear_bit(0, event->flags)) |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1280 | handled = true; |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1281 | } else { |
| 1282 | /* |
| 1283 | * Our host is win8 or above. The signaling mechanism |
| 1284 | * has changed and we can directly look at the event page. |
| 1285 | * If bit n is set then we have an interrup on the channel |
| 1286 | * whose id is n. |
| 1287 | */ |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1288 | handled = true; |
K. Y. Srinivasan | 793be9c | 2011-03-15 15:03:43 -0700 | [diff] [blame] | 1289 | } |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1290 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1291 | if (handled) |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1292 | vmbus_chan_sched(hv_cpu); |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1293 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1294 | page_addr = hv_cpu->synic_message_page; |
K. Y. Srinivasan | 7341d90 | 2011-08-31 14:35:56 -0700 | [diff] [blame] | 1295 | msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; |
| 1296 | |
| 1297 | /* Check if there are actual msgs to be processed */ |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 1298 | if (msg->header.message_type != HVMSG_NONE) { |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1299 | if (msg->header.message_type == HVMSG_TIMER_EXPIRED) { |
| 1300 | hv_stimer0_isr(); |
| 1301 | vmbus_signal_eom(msg, HVMSG_TIMER_EXPIRED); |
| 1302 | } else |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1303 | tasklet_schedule(&hv_cpu->msg_dpc); |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 1304 | } |
Stephan Mueller | 4b44f2d | 2016-05-02 02:14:34 -0400 | [diff] [blame] | 1305 | |
| 1306 | add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0); |
K. Y. Srinivasan | 793be9c | 2011-03-15 15:03:43 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1309 | /* |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1310 | * Callback from kmsg_dump. Grab as much as possible from the end of the kmsg |
| 1311 | * buffer and call into Hyper-V to transfer the data. |
| 1312 | */ |
| 1313 | static void hv_kmsg_dump(struct kmsg_dumper *dumper, |
| 1314 | enum kmsg_dump_reason reason) |
| 1315 | { |
| 1316 | size_t bytes_written; |
| 1317 | phys_addr_t panic_pa; |
| 1318 | |
| 1319 | /* We are only interested in panics. */ |
| 1320 | if ((reason != KMSG_DUMP_PANIC) || (!sysctl_record_panic_msg)) |
| 1321 | return; |
| 1322 | |
| 1323 | panic_pa = virt_to_phys(hv_panic_page); |
| 1324 | |
| 1325 | /* |
| 1326 | * Write dump contents to the page. No need to synchronize; panic should |
| 1327 | * be single-threaded. |
| 1328 | */ |
Himadri Pandya | 53edce0 | 2019-07-30 09:49:44 +0000 | [diff] [blame] | 1329 | kmsg_dump_get_buffer(dumper, true, hv_panic_page, HV_HYP_PAGE_SIZE, |
Sunil Muthuswamy | ddcaf3c | 2018-07-28 21:58:45 +0000 | [diff] [blame] | 1330 | &bytes_written); |
| 1331 | if (bytes_written) |
| 1332 | hyperv_report_panic_msg(panic_pa, bytes_written); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | static struct kmsg_dumper hv_kmsg_dumper = { |
| 1336 | .dump = hv_kmsg_dump, |
| 1337 | }; |
| 1338 | |
| 1339 | static struct ctl_table_header *hv_ctl_table_hdr; |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1340 | |
| 1341 | /* |
| 1342 | * sysctl option to allow the user to control whether kmsg data should be |
| 1343 | * reported to Hyper-V on panic. |
| 1344 | */ |
| 1345 | static struct ctl_table hv_ctl_table[] = { |
| 1346 | { |
| 1347 | .procname = "hyperv_record_panic_msg", |
| 1348 | .data = &sysctl_record_panic_msg, |
| 1349 | .maxlen = sizeof(int), |
| 1350 | .mode = 0644, |
| 1351 | .proc_handler = proc_dointvec_minmax, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 1352 | .extra1 = SYSCTL_ZERO, |
| 1353 | .extra2 = SYSCTL_ONE |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1354 | }, |
| 1355 | {} |
| 1356 | }; |
| 1357 | |
| 1358 | static struct ctl_table hv_root_table[] = { |
| 1359 | { |
| 1360 | .procname = "kernel", |
| 1361 | .mode = 0555, |
| 1362 | .child = hv_ctl_table |
| 1363 | }, |
| 1364 | {} |
| 1365 | }; |
Vitaly Kuznetsov | e513229 | 2015-02-27 11:25:51 -0800 | [diff] [blame] | 1366 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1367 | /* |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1368 | * vmbus_bus_init -Main vmbus driver initialization routine. |
| 1369 | * |
| 1370 | * Here, we |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1371 | * - initialize the vmbus driver context |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1372 | * - invoke the vmbus hv main init routine |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1373 | * - retrieve the channel offers |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1374 | */ |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 1375 | static int vmbus_bus_init(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1376 | { |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1377 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1378 | |
Greg Kroah-Hartman | 6d26e38fa2 | 2010-12-02 12:08:08 -0800 | [diff] [blame] | 1379 | /* Hypervisor initialization...setup hypercall page..etc */ |
| 1380 | ret = hv_init(); |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1381 | if (ret != 0) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1382 | pr_err("Unable to initialize the hypervisor - 0x%x\n", ret); |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1383 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
K. Y. Srinivasan | 9adcac5 | 2011-04-29 13:45:08 -0700 | [diff] [blame] | 1386 | ret = bus_register(&hv_bus); |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1387 | if (ret) |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 1388 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1389 | |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1390 | hv_setup_vmbus_irq(vmbus_isr); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1391 | |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 1392 | ret = hv_synic_alloc(); |
| 1393 | if (ret) |
| 1394 | goto err_alloc; |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1395 | |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1396 | /* |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1397 | * Initialize the per-cpu interrupt state and stimer state. |
| 1398 | * Then connect to the host. |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1399 | */ |
Michael Kelley | 4a5f3cd | 2017-12-22 11:19:02 -0700 | [diff] [blame] | 1400 | ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online", |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 1401 | hv_synic_init, hv_synic_cleanup); |
| 1402 | if (ret < 0) |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1403 | goto err_cpuhp; |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 1404 | hyperv_cpuhp_online = ret; |
| 1405 | |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1406 | ret = vmbus_connect(); |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1407 | if (ret) |
Andrey Smetanin | 17efbee | 2015-12-14 16:01:38 -0800 | [diff] [blame] | 1408 | goto err_connect; |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1409 | |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 1410 | /* |
| 1411 | * Only register if the crash MSRs are available |
| 1412 | */ |
Denis V. Lunev | cc2dd40 | 2015-08-01 16:08:20 -0700 | [diff] [blame] | 1413 | if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) { |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1414 | u64 hyperv_crash_ctl; |
| 1415 | /* |
| 1416 | * Sysctl registration is not fatal, since by default |
| 1417 | * reporting is enabled. |
| 1418 | */ |
| 1419 | hv_ctl_table_hdr = register_sysctl_table(hv_root_table); |
| 1420 | if (!hv_ctl_table_hdr) |
| 1421 | pr_err("Hyper-V: sysctl table register error"); |
| 1422 | |
| 1423 | /* |
| 1424 | * Register for panic kmsg callback only if the right |
| 1425 | * capability is supported by the hypervisor. |
| 1426 | */ |
Sunil Muthuswamy | 9d9c965 | 2018-07-28 21:58:47 +0000 | [diff] [blame] | 1427 | hv_get_crash_ctl(hyperv_crash_ctl); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1428 | if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG) { |
Himadri Pandya | 53edce0 | 2019-07-30 09:49:44 +0000 | [diff] [blame] | 1429 | hv_panic_page = (void *)hv_alloc_hyperv_zeroed_page(); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1430 | if (hv_panic_page) { |
| 1431 | ret = kmsg_dump_register(&hv_kmsg_dumper); |
Tianyu Lan | 7f11a2c | 2020-04-06 08:53:27 -0700 | [diff] [blame] | 1432 | if (ret) { |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1433 | pr_err("Hyper-V: kmsg dump register " |
| 1434 | "error 0x%x\n", ret); |
Tianyu Lan | 7f11a2c | 2020-04-06 08:53:27 -0700 | [diff] [blame] | 1435 | hv_free_hyperv_page( |
| 1436 | (unsigned long)hv_panic_page); |
| 1437 | hv_panic_page = NULL; |
| 1438 | } |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1439 | } else |
| 1440 | pr_err("Hyper-V: panic message page memory " |
| 1441 | "allocation failed"); |
| 1442 | } |
| 1443 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 1444 | register_die_notifier(&hyperv_die_block); |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 1445 | } |
| 1446 | |
Tianyu Lan | 74347a9 | 2020-04-06 08:53:26 -0700 | [diff] [blame] | 1447 | /* |
| 1448 | * Always register the panic notifier because we need to unload |
| 1449 | * the VMbus channel connection to prevent any VMbus |
| 1450 | * activity after the VM panics. |
| 1451 | */ |
| 1452 | atomic_notifier_chain_register(&panic_notifier_list, |
| 1453 | &hyperv_panic_block); |
| 1454 | |
Greg Kroah-Hartman | 2d6e882 | 2010-12-02 08:50:58 -0800 | [diff] [blame] | 1455 | vmbus_request_offers(); |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 1456 | |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1457 | return 0; |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1458 | |
Andrey Smetanin | 17efbee | 2015-12-14 16:01:38 -0800 | [diff] [blame] | 1459 | err_connect: |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 1460 | cpuhp_remove_state(hyperv_cpuhp_online); |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 1461 | err_cpuhp: |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 1462 | hv_synic_free(); |
Michael Kelley | 4df4cb9e9 | 2019-11-13 01:11:49 +0000 | [diff] [blame] | 1463 | err_alloc: |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1464 | hv_remove_vmbus_irq(); |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1465 | |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1466 | bus_unregister(&hv_bus); |
Sunil Muthuswamy | 8afc06d | 2018-07-28 21:58:46 +0000 | [diff] [blame] | 1467 | unregister_sysctl_table(hv_ctl_table_hdr); |
| 1468 | hv_ctl_table_hdr = NULL; |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1469 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1472 | /** |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1473 | * __vmbus_child_driver_register() - Register a vmbus's driver |
| 1474 | * @hv_driver: Pointer to driver structure you want to register |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1475 | * @owner: owner module of the drv |
| 1476 | * @mod_name: module name string |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1477 | * |
| 1478 | * Registers the given driver with Linux through the 'driver_register()' call |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1479 | * and sets up the hyper-v vmbus handling for this driver. |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1480 | * It will return the state of the 'driver_register()' call. |
| 1481 | * |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1482 | */ |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1483 | int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, const char *mod_name) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1484 | { |
Bill Pemberton | 5d48a1c | 2009-07-27 16:47:36 -0400 | [diff] [blame] | 1485 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1486 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1487 | pr_info("registering driver %s\n", hv_driver->name); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1488 | |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 1489 | ret = vmbus_exists(); |
| 1490 | if (ret < 0) |
| 1491 | return ret; |
| 1492 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1493 | hv_driver->driver.name = hv_driver->name; |
| 1494 | hv_driver->driver.owner = owner; |
| 1495 | hv_driver->driver.mod_name = mod_name; |
| 1496 | hv_driver->driver.bus = &hv_bus; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1497 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1498 | spin_lock_init(&hv_driver->dynids.lock); |
| 1499 | INIT_LIST_HEAD(&hv_driver->dynids.list); |
| 1500 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1501 | ret = driver_register(&hv_driver->driver); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1502 | |
Bill Pemberton | 5d48a1c | 2009-07-27 16:47:36 -0400 | [diff] [blame] | 1503 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1504 | } |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1505 | EXPORT_SYMBOL_GPL(__vmbus_driver_register); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1506 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1507 | /** |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1508 | * vmbus_driver_unregister() - Unregister a vmbus's driver |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1509 | * @hv_driver: Pointer to driver structure you want to |
| 1510 | * un-register |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1511 | * |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1512 | * Un-register the given driver that was previous registered with a call to |
| 1513 | * vmbus_driver_register() |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1514 | */ |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1515 | void vmbus_driver_unregister(struct hv_driver *hv_driver) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1516 | { |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1517 | pr_info("unregistering driver %s\n", hv_driver->name); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1518 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1519 | if (!vmbus_exists()) { |
K. Y. Srinivasan | 8f257a1 | 2011-12-27 13:49:37 -0800 | [diff] [blame] | 1520 | driver_unregister(&hv_driver->driver); |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1521 | vmbus_free_dynids(hv_driver); |
| 1522 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1523 | } |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1524 | EXPORT_SYMBOL_GPL(vmbus_driver_unregister); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1525 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1526 | |
| 1527 | /* |
| 1528 | * Called when last reference to channel is gone. |
| 1529 | */ |
| 1530 | static void vmbus_chan_release(struct kobject *kobj) |
| 1531 | { |
| 1532 | struct vmbus_channel *channel |
| 1533 | = container_of(kobj, struct vmbus_channel, kobj); |
| 1534 | |
| 1535 | kfree_rcu(channel, rcu); |
| 1536 | } |
| 1537 | |
| 1538 | struct vmbus_chan_attribute { |
| 1539 | struct attribute attr; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1540 | ssize_t (*show)(struct vmbus_channel *chan, char *buf); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1541 | ssize_t (*store)(struct vmbus_channel *chan, |
| 1542 | const char *buf, size_t count); |
| 1543 | }; |
| 1544 | #define VMBUS_CHAN_ATTR(_name, _mode, _show, _store) \ |
| 1545 | struct vmbus_chan_attribute chan_attr_##_name \ |
| 1546 | = __ATTR(_name, _mode, _show, _store) |
| 1547 | #define VMBUS_CHAN_ATTR_RW(_name) \ |
| 1548 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_RW(_name) |
| 1549 | #define VMBUS_CHAN_ATTR_RO(_name) \ |
| 1550 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_RO(_name) |
| 1551 | #define VMBUS_CHAN_ATTR_WO(_name) \ |
| 1552 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_WO(_name) |
| 1553 | |
| 1554 | static ssize_t vmbus_chan_attr_show(struct kobject *kobj, |
| 1555 | struct attribute *attr, char *buf) |
| 1556 | { |
| 1557 | const struct vmbus_chan_attribute *attribute |
| 1558 | = container_of(attr, struct vmbus_chan_attribute, attr); |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1559 | struct vmbus_channel *chan |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1560 | = container_of(kobj, struct vmbus_channel, kobj); |
| 1561 | |
| 1562 | if (!attribute->show) |
| 1563 | return -EIO; |
| 1564 | |
| 1565 | return attribute->show(chan, buf); |
| 1566 | } |
| 1567 | |
| 1568 | static const struct sysfs_ops vmbus_chan_sysfs_ops = { |
| 1569 | .show = vmbus_chan_attr_show, |
| 1570 | }; |
| 1571 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1572 | static ssize_t out_mask_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1573 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1574 | struct hv_ring_buffer_info *rbi = &channel->outbound; |
| 1575 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1576 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1577 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1578 | if (!rbi->ring_buffer) { |
| 1579 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1580 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1581 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1582 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1583 | ret = sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); |
| 1584 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1585 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1586 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1587 | static VMBUS_CHAN_ATTR_RO(out_mask); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1588 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1589 | static ssize_t in_mask_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1590 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1591 | struct hv_ring_buffer_info *rbi = &channel->inbound; |
| 1592 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1593 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1594 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1595 | if (!rbi->ring_buffer) { |
| 1596 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1597 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1598 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1599 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1600 | ret = sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); |
| 1601 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1602 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1603 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1604 | static VMBUS_CHAN_ATTR_RO(in_mask); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1605 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1606 | static ssize_t read_avail_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1607 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1608 | struct hv_ring_buffer_info *rbi = &channel->inbound; |
| 1609 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1610 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1611 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1612 | if (!rbi->ring_buffer) { |
| 1613 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1614 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1615 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1616 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1617 | ret = sprintf(buf, "%u\n", hv_get_bytes_to_read(rbi)); |
| 1618 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1619 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1620 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1621 | static VMBUS_CHAN_ATTR_RO(read_avail); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1622 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1623 | static ssize_t write_avail_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1624 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1625 | struct hv_ring_buffer_info *rbi = &channel->outbound; |
| 1626 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1627 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1628 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1629 | if (!rbi->ring_buffer) { |
| 1630 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1631 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1632 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1633 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1634 | ret = sprintf(buf, "%u\n", hv_get_bytes_to_write(rbi)); |
| 1635 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1636 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1637 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1638 | static VMBUS_CHAN_ATTR_RO(write_avail); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1639 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1640 | static ssize_t show_target_cpu(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1641 | { |
| 1642 | return sprintf(buf, "%u\n", channel->target_cpu); |
| 1643 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1644 | static VMBUS_CHAN_ATTR(cpu, S_IRUGO, show_target_cpu, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1645 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1646 | static ssize_t channel_pending_show(struct vmbus_channel *channel, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1647 | char *buf) |
| 1648 | { |
| 1649 | return sprintf(buf, "%d\n", |
| 1650 | channel_pending(channel, |
| 1651 | vmbus_connection.monitor_pages[1])); |
| 1652 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1653 | static VMBUS_CHAN_ATTR(pending, S_IRUGO, channel_pending_show, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1654 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1655 | static ssize_t channel_latency_show(struct vmbus_channel *channel, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1656 | char *buf) |
| 1657 | { |
| 1658 | return sprintf(buf, "%d\n", |
| 1659 | channel_latency(channel, |
| 1660 | vmbus_connection.monitor_pages[1])); |
| 1661 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1662 | static VMBUS_CHAN_ATTR(latency, S_IRUGO, channel_latency_show, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1663 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1664 | static ssize_t channel_interrupts_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1665 | { |
| 1666 | return sprintf(buf, "%llu\n", channel->interrupts); |
| 1667 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1668 | static VMBUS_CHAN_ATTR(interrupts, S_IRUGO, channel_interrupts_show, NULL); |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1669 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1670 | static ssize_t channel_events_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1671 | { |
| 1672 | return sprintf(buf, "%llu\n", channel->sig_events); |
| 1673 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1674 | static VMBUS_CHAN_ATTR(events, S_IRUGO, channel_events_show, NULL); |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1675 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1676 | static ssize_t channel_intr_in_full_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1677 | char *buf) |
| 1678 | { |
| 1679 | return sprintf(buf, "%llu\n", |
| 1680 | (unsigned long long)channel->intr_in_full); |
| 1681 | } |
| 1682 | static VMBUS_CHAN_ATTR(intr_in_full, 0444, channel_intr_in_full_show, NULL); |
| 1683 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1684 | static ssize_t channel_intr_out_empty_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1685 | char *buf) |
| 1686 | { |
| 1687 | return sprintf(buf, "%llu\n", |
| 1688 | (unsigned long long)channel->intr_out_empty); |
| 1689 | } |
| 1690 | static VMBUS_CHAN_ATTR(intr_out_empty, 0444, channel_intr_out_empty_show, NULL); |
| 1691 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1692 | static ssize_t channel_out_full_first_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1693 | char *buf) |
| 1694 | { |
| 1695 | return sprintf(buf, "%llu\n", |
| 1696 | (unsigned long long)channel->out_full_first); |
| 1697 | } |
| 1698 | static VMBUS_CHAN_ATTR(out_full_first, 0444, channel_out_full_first_show, NULL); |
| 1699 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1700 | static ssize_t channel_out_full_total_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1701 | char *buf) |
| 1702 | { |
| 1703 | return sprintf(buf, "%llu\n", |
| 1704 | (unsigned long long)channel->out_full_total); |
| 1705 | } |
| 1706 | static VMBUS_CHAN_ATTR(out_full_total, 0444, channel_out_full_total_show, NULL); |
| 1707 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1708 | static ssize_t subchannel_monitor_id_show(struct vmbus_channel *channel, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1709 | char *buf) |
| 1710 | { |
| 1711 | return sprintf(buf, "%u\n", channel->offermsg.monitorid); |
| 1712 | } |
| 1713 | static VMBUS_CHAN_ATTR(monitor_id, S_IRUGO, subchannel_monitor_id_show, NULL); |
| 1714 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1715 | static ssize_t subchannel_id_show(struct vmbus_channel *channel, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1716 | char *buf) |
| 1717 | { |
| 1718 | return sprintf(buf, "%u\n", |
| 1719 | channel->offermsg.offer.sub_channel_index); |
| 1720 | } |
| 1721 | static VMBUS_CHAN_ATTR_RO(subchannel_id); |
| 1722 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1723 | static struct attribute *vmbus_chan_attrs[] = { |
| 1724 | &chan_attr_out_mask.attr, |
| 1725 | &chan_attr_in_mask.attr, |
| 1726 | &chan_attr_read_avail.attr, |
| 1727 | &chan_attr_write_avail.attr, |
| 1728 | &chan_attr_cpu.attr, |
| 1729 | &chan_attr_pending.attr, |
| 1730 | &chan_attr_latency.attr, |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1731 | &chan_attr_interrupts.attr, |
| 1732 | &chan_attr_events.attr, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1733 | &chan_attr_intr_in_full.attr, |
| 1734 | &chan_attr_intr_out_empty.attr, |
| 1735 | &chan_attr_out_full_first.attr, |
| 1736 | &chan_attr_out_full_total.attr, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1737 | &chan_attr_monitor_id.attr, |
| 1738 | &chan_attr_subchannel_id.attr, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1739 | NULL |
| 1740 | }; |
| 1741 | |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1742 | /* |
| 1743 | * Channel-level attribute_group callback function. Returns the permission for |
| 1744 | * each attribute, and returns 0 if an attribute is not visible. |
| 1745 | */ |
| 1746 | static umode_t vmbus_chan_attr_is_visible(struct kobject *kobj, |
| 1747 | struct attribute *attr, int idx) |
| 1748 | { |
| 1749 | const struct vmbus_channel *channel = |
| 1750 | container_of(kobj, struct vmbus_channel, kobj); |
| 1751 | |
| 1752 | /* Hide the monitor attributes if the monitor mechanism is not used. */ |
| 1753 | if (!channel->offermsg.monitor_allocated && |
| 1754 | (attr == &chan_attr_pending.attr || |
| 1755 | attr == &chan_attr_latency.attr || |
| 1756 | attr == &chan_attr_monitor_id.attr)) |
| 1757 | return 0; |
| 1758 | |
| 1759 | return attr->mode; |
| 1760 | } |
| 1761 | |
| 1762 | static struct attribute_group vmbus_chan_group = { |
| 1763 | .attrs = vmbus_chan_attrs, |
| 1764 | .is_visible = vmbus_chan_attr_is_visible |
| 1765 | }; |
| 1766 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1767 | static struct kobj_type vmbus_chan_ktype = { |
| 1768 | .sysfs_ops = &vmbus_chan_sysfs_ops, |
| 1769 | .release = vmbus_chan_release, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1770 | }; |
| 1771 | |
| 1772 | /* |
| 1773 | * vmbus_add_channel_kobj - setup a sub-directory under device/channels |
| 1774 | */ |
| 1775 | int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) |
| 1776 | { |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1777 | const struct device *device = &dev->device; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1778 | struct kobject *kobj = &channel->kobj; |
| 1779 | u32 relid = channel->offermsg.child_relid; |
| 1780 | int ret; |
| 1781 | |
| 1782 | kobj->kset = dev->channels_kset; |
| 1783 | ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL, |
| 1784 | "%u", relid); |
| 1785 | if (ret) |
| 1786 | return ret; |
| 1787 | |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1788 | ret = sysfs_create_group(kobj, &vmbus_chan_group); |
| 1789 | |
| 1790 | if (ret) { |
| 1791 | /* |
| 1792 | * The calling functions' error handling paths will cleanup the |
| 1793 | * empty channel directory. |
| 1794 | */ |
| 1795 | dev_err(device, "Unable to set up channel sysfs files\n"); |
| 1796 | return ret; |
| 1797 | } |
| 1798 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1799 | kobject_uevent(kobj, KOBJ_ADD); |
| 1800 | |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1804 | /* |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1805 | * vmbus_remove_channel_attr_group - remove the channel's attribute group |
| 1806 | */ |
| 1807 | void vmbus_remove_channel_attr_group(struct vmbus_channel *channel) |
| 1808 | { |
| 1809 | sysfs_remove_group(&channel->kobj, &vmbus_chan_group); |
| 1810 | } |
| 1811 | |
| 1812 | /* |
K. Y. Srinivasan | f2c7301 | 2011-09-08 07:24:12 -0700 | [diff] [blame] | 1813 | * vmbus_device_create - Creates and registers a new child device |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1814 | * on the vmbus. |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1815 | */ |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 1816 | struct hv_device *vmbus_device_create(const guid_t *type, |
| 1817 | const guid_t *instance, |
stephen hemminger | 1b9d48f | 2014-06-03 08:38:15 -0700 | [diff] [blame] | 1818 | struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1819 | { |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 1820 | struct hv_device *child_device_obj; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1821 | |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1822 | child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL); |
| 1823 | if (!child_device_obj) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1824 | pr_err("Unable to allocate device object for child device\n"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1825 | return NULL; |
| 1826 | } |
| 1827 | |
Greg Kroah-Hartman | cae5b84 | 2010-10-21 09:05:27 -0700 | [diff] [blame] | 1828 | child_device_obj->channel = channel; |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 1829 | guid_copy(&child_device_obj->dev_type, type); |
| 1830 | guid_copy(&child_device_obj->dev_instance, instance); |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 1831 | child_device_obj->vendor_id = 0x1414; /* MSFT vendor ID */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1832 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1833 | return child_device_obj; |
| 1834 | } |
| 1835 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1836 | /* |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 1837 | * vmbus_device_register - Register the child device |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1838 | */ |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 1839 | int vmbus_device_register(struct hv_device *child_device_obj) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1840 | { |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1841 | struct kobject *kobj = &child_device_obj->device.kobj; |
| 1842 | int ret; |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1843 | |
Stephen Hemminger | f6b2db0 | 2016-11-01 00:01:59 -0700 | [diff] [blame] | 1844 | dev_set_name(&child_device_obj->device, "%pUl", |
Vitaly Kuznetsov | b294809 | 2016-09-16 09:01:17 -0700 | [diff] [blame] | 1845 | child_device_obj->channel->offermsg.offer.if_instance.b); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1846 | |
K. Y. Srinivasan | 0bce28b | 2011-08-27 11:31:39 -0700 | [diff] [blame] | 1847 | child_device_obj->device.bus = &hv_bus; |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 1848 | child_device_obj->device.parent = &hv_acpi_dev->dev; |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1849 | child_device_obj->device.release = vmbus_device_release; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1850 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1851 | /* |
| 1852 | * Register with the LDM. This will kick off the driver/device |
| 1853 | * binding...which will eventually call vmbus_match() and vmbus_probe() |
| 1854 | */ |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1855 | ret = device_register(&child_device_obj->device); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1856 | if (ret) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1857 | pr_err("Unable to register child device\n"); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1858 | return ret; |
| 1859 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1860 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1861 | child_device_obj->channels_kset = kset_create_and_add("channels", |
| 1862 | NULL, kobj); |
| 1863 | if (!child_device_obj->channels_kset) { |
| 1864 | ret = -ENOMEM; |
| 1865 | goto err_dev_unregister; |
| 1866 | } |
| 1867 | |
| 1868 | ret = vmbus_add_channel_kobj(child_device_obj, |
| 1869 | child_device_obj->channel); |
| 1870 | if (ret) { |
| 1871 | pr_err("Unable to register primary channeln"); |
| 1872 | goto err_kset_unregister; |
| 1873 | } |
Branden Bonaby | af9ca6f | 2019-10-03 17:01:49 -0400 | [diff] [blame] | 1874 | hv_debug_add_dev_dir(child_device_obj); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1875 | |
| 1876 | return 0; |
| 1877 | |
| 1878 | err_kset_unregister: |
| 1879 | kset_unregister(child_device_obj->channels_kset); |
| 1880 | |
| 1881 | err_dev_unregister: |
| 1882 | device_unregister(&child_device_obj->device); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1883 | return ret; |
| 1884 | } |
| 1885 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1886 | /* |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 1887 | * vmbus_device_unregister - Remove the specified child device |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1888 | * from the vmbus. |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1889 | */ |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 1890 | void vmbus_device_unregister(struct hv_device *device_obj) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1891 | { |
Fernando Soto | 8467236 | 2013-06-14 23:13:35 +0000 | [diff] [blame] | 1892 | pr_debug("child device %s unregistered\n", |
| 1893 | dev_name(&device_obj->device)); |
| 1894 | |
Dexuan Cui | 869b556 | 2017-11-14 06:53:32 -0700 | [diff] [blame] | 1895 | kset_unregister(device_obj->channels_kset); |
| 1896 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1897 | /* |
| 1898 | * Kick off the process of unregistering the device. |
| 1899 | * This will call vmbus_remove() and eventually vmbus_device_release() |
| 1900 | */ |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1901 | device_unregister(&device_obj->device); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1904 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1905 | /* |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1906 | * VMBUS is an acpi enumerated device. Get the information we |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1907 | * need from DSDT. |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1908 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1909 | #define VTPM_BASE_ADDRESS 0xfed40000 |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1910 | static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx) |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1911 | { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1912 | resource_size_t start = 0; |
| 1913 | resource_size_t end = 0; |
| 1914 | struct resource *new_res; |
| 1915 | struct resource **old_res = &hyperv_mmio; |
| 1916 | struct resource **prev_res = NULL; |
| 1917 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1918 | switch (res->type) { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1919 | |
| 1920 | /* |
| 1921 | * "Address" descriptors are for bus windows. Ignore |
| 1922 | * "memory" descriptors, which are for registers on |
| 1923 | * devices. |
| 1924 | */ |
| 1925 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
| 1926 | start = res->data.address32.address.minimum; |
| 1927 | end = res->data.address32.address.maximum; |
Gerd Hoffmann | 4eb923f | 2014-02-24 14:17:08 +0100 | [diff] [blame] | 1928 | break; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1929 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1930 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1931 | start = res->data.address64.address.minimum; |
| 1932 | end = res->data.address64.address.maximum; |
Gerd Hoffmann | 4eb923f | 2014-02-24 14:17:08 +0100 | [diff] [blame] | 1933 | break; |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1934 | |
| 1935 | default: |
| 1936 | /* Unused resource type */ |
| 1937 | return AE_OK; |
| 1938 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1939 | } |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1940 | /* |
| 1941 | * Ignore ranges that are below 1MB, as they're not |
| 1942 | * necessary or useful here. |
| 1943 | */ |
| 1944 | if (end < 0x100000) |
| 1945 | return AE_OK; |
| 1946 | |
| 1947 | new_res = kzalloc(sizeof(*new_res), GFP_ATOMIC); |
| 1948 | if (!new_res) |
| 1949 | return AE_NO_MEMORY; |
| 1950 | |
| 1951 | /* If this range overlaps the virtual TPM, truncate it. */ |
| 1952 | if (end > VTPM_BASE_ADDRESS && start < VTPM_BASE_ADDRESS) |
| 1953 | end = VTPM_BASE_ADDRESS; |
| 1954 | |
| 1955 | new_res->name = "hyperv mmio"; |
| 1956 | new_res->flags = IORESOURCE_MEM; |
| 1957 | new_res->start = start; |
| 1958 | new_res->end = end; |
| 1959 | |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1960 | /* |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1961 | * If two ranges are adjacent, merge them. |
| 1962 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1963 | do { |
| 1964 | if (!*old_res) { |
| 1965 | *old_res = new_res; |
| 1966 | break; |
| 1967 | } |
| 1968 | |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1969 | if (((*old_res)->end + 1) == new_res->start) { |
| 1970 | (*old_res)->end = new_res->end; |
| 1971 | kfree(new_res); |
| 1972 | break; |
| 1973 | } |
| 1974 | |
| 1975 | if ((*old_res)->start == new_res->end + 1) { |
| 1976 | (*old_res)->start = new_res->start; |
| 1977 | kfree(new_res); |
| 1978 | break; |
| 1979 | } |
| 1980 | |
Jake Oshins | 23a0683 | 2016-04-05 10:22:53 -0700 | [diff] [blame] | 1981 | if ((*old_res)->start > new_res->end) { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1982 | new_res->sibling = *old_res; |
| 1983 | if (prev_res) |
| 1984 | (*prev_res)->sibling = new_res; |
| 1985 | *old_res = new_res; |
| 1986 | break; |
| 1987 | } |
| 1988 | |
| 1989 | prev_res = old_res; |
| 1990 | old_res = &(*old_res)->sibling; |
| 1991 | |
| 1992 | } while (1); |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1993 | |
| 1994 | return AE_OK; |
| 1995 | } |
| 1996 | |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1997 | static int vmbus_acpi_remove(struct acpi_device *device) |
| 1998 | { |
| 1999 | struct resource *cur_res; |
| 2000 | struct resource *next_res; |
| 2001 | |
| 2002 | if (hyperv_mmio) { |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 2003 | if (fb_mmio) { |
| 2004 | __release_region(hyperv_mmio, fb_mmio->start, |
| 2005 | resource_size(fb_mmio)); |
| 2006 | fb_mmio = NULL; |
| 2007 | } |
| 2008 | |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2009 | for (cur_res = hyperv_mmio; cur_res; cur_res = next_res) { |
| 2010 | next_res = cur_res->sibling; |
| 2011 | kfree(cur_res); |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | return 0; |
| 2016 | } |
| 2017 | |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 2018 | static void vmbus_reserve_fb(void) |
| 2019 | { |
| 2020 | int size; |
| 2021 | /* |
| 2022 | * Make a claim for the frame buffer in the resource tree under the |
| 2023 | * first node, which will be the one below 4GB. The length seems to |
| 2024 | * be underreported, particularly in a Generation 1 VM. So start out |
| 2025 | * reserving a larger area and make it smaller until it succeeds. |
| 2026 | */ |
| 2027 | |
| 2028 | if (screen_info.lfb_base) { |
| 2029 | if (efi_enabled(EFI_BOOT)) |
| 2030 | size = max_t(__u32, screen_info.lfb_size, 0x800000); |
| 2031 | else |
| 2032 | size = max_t(__u32, screen_info.lfb_size, 0x4000000); |
| 2033 | |
| 2034 | for (; !fb_mmio && (size >= 0x100000); size >>= 1) { |
| 2035 | fb_mmio = __request_region(hyperv_mmio, |
| 2036 | screen_info.lfb_base, size, |
| 2037 | fb_mmio_name, 0); |
| 2038 | } |
| 2039 | } |
| 2040 | } |
| 2041 | |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 2042 | /** |
| 2043 | * vmbus_allocate_mmio() - Pick a memory-mapped I/O range. |
| 2044 | * @new: If successful, supplied a pointer to the |
| 2045 | * allocated MMIO space. |
| 2046 | * @device_obj: Identifies the caller |
| 2047 | * @min: Minimum guest physical address of the |
| 2048 | * allocation |
| 2049 | * @max: Maximum guest physical address |
| 2050 | * @size: Size of the range to be allocated |
| 2051 | * @align: Alignment of the range to be allocated |
| 2052 | * @fb_overlap_ok: Whether this allocation can be allowed |
| 2053 | * to overlap the video frame buffer. |
| 2054 | * |
| 2055 | * This function walks the resources granted to VMBus by the |
| 2056 | * _CRS object in the ACPI namespace underneath the parent |
| 2057 | * "bridge" whether that's a root PCI bus in the Generation 1 |
| 2058 | * case or a Module Device in the Generation 2 case. It then |
| 2059 | * attempts to allocate from the global MMIO pool in a way that |
| 2060 | * matches the constraints supplied in these parameters and by |
| 2061 | * that _CRS. |
| 2062 | * |
| 2063 | * Return: 0 on success, -errno on failure |
| 2064 | */ |
| 2065 | int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, |
| 2066 | resource_size_t min, resource_size_t max, |
| 2067 | resource_size_t size, resource_size_t align, |
| 2068 | bool fb_overlap_ok) |
| 2069 | { |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 2070 | struct resource *iter, *shadow; |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 2071 | resource_size_t range_min, range_max, start; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 2072 | const char *dev_n = dev_name(&device_obj->device); |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 2073 | int retval; |
Jake Oshins | e16dad6 | 2016-04-05 10:22:50 -0700 | [diff] [blame] | 2074 | |
| 2075 | retval = -ENXIO; |
Davidlohr Bueso | 8aea7f8 | 2019-11-01 13:00:04 -0700 | [diff] [blame] | 2076 | mutex_lock(&hyperv_mmio_lock); |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 2077 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 2078 | /* |
| 2079 | * If overlaps with frame buffers are allowed, then first attempt to |
| 2080 | * make the allocation from within the reserved region. Because it |
| 2081 | * is already reserved, no shadow allocation is necessary. |
| 2082 | */ |
| 2083 | if (fb_overlap_ok && fb_mmio && !(min > fb_mmio->end) && |
| 2084 | !(max < fb_mmio->start)) { |
| 2085 | |
| 2086 | range_min = fb_mmio->start; |
| 2087 | range_max = fb_mmio->end; |
| 2088 | start = (range_min + align - 1) & ~(align - 1); |
| 2089 | for (; start + size - 1 <= range_max; start += align) { |
| 2090 | *new = request_mem_region_exclusive(start, size, dev_n); |
| 2091 | if (*new) { |
| 2092 | retval = 0; |
| 2093 | goto exit; |
| 2094 | } |
| 2095 | } |
| 2096 | } |
| 2097 | |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 2098 | for (iter = hyperv_mmio; iter; iter = iter->sibling) { |
| 2099 | if ((iter->start >= max) || (iter->end <= min)) |
| 2100 | continue; |
| 2101 | |
| 2102 | range_min = iter->start; |
| 2103 | range_max = iter->end; |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 2104 | start = (range_min + align - 1) & ~(align - 1); |
| 2105 | for (; start + size - 1 <= range_max; start += align) { |
| 2106 | shadow = __request_region(iter, start, size, NULL, |
| 2107 | IORESOURCE_BUSY); |
| 2108 | if (!shadow) |
| 2109 | continue; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 2110 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 2111 | *new = request_mem_region_exclusive(start, size, dev_n); |
| 2112 | if (*new) { |
| 2113 | shadow->name = (char *)*new; |
| 2114 | retval = 0; |
| 2115 | goto exit; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 2118 | __release_region(iter, start, size); |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | |
Jake Oshins | e16dad6 | 2016-04-05 10:22:50 -0700 | [diff] [blame] | 2122 | exit: |
Davidlohr Bueso | 8aea7f8 | 2019-11-01 13:00:04 -0700 | [diff] [blame] | 2123 | mutex_unlock(&hyperv_mmio_lock); |
Jake Oshins | e16dad6 | 2016-04-05 10:22:50 -0700 | [diff] [blame] | 2124 | return retval; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 2125 | } |
| 2126 | EXPORT_SYMBOL_GPL(vmbus_allocate_mmio); |
| 2127 | |
Jake Oshins | 619848b | 2015-12-14 16:01:39 -0800 | [diff] [blame] | 2128 | /** |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 2129 | * vmbus_free_mmio() - Free a memory-mapped I/O range. |
| 2130 | * @start: Base address of region to release. |
| 2131 | * @size: Size of the range to be allocated |
| 2132 | * |
| 2133 | * This function releases anything requested by |
| 2134 | * vmbus_mmio_allocate(). |
| 2135 | */ |
| 2136 | void vmbus_free_mmio(resource_size_t start, resource_size_t size) |
| 2137 | { |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 2138 | struct resource *iter; |
| 2139 | |
Davidlohr Bueso | 8aea7f8 | 2019-11-01 13:00:04 -0700 | [diff] [blame] | 2140 | mutex_lock(&hyperv_mmio_lock); |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 2141 | for (iter = hyperv_mmio; iter; iter = iter->sibling) { |
| 2142 | if ((iter->start >= start + size) || (iter->end <= start)) |
| 2143 | continue; |
| 2144 | |
| 2145 | __release_region(iter, start, size); |
| 2146 | } |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 2147 | release_mem_region(start, size); |
Davidlohr Bueso | 8aea7f8 | 2019-11-01 13:00:04 -0700 | [diff] [blame] | 2148 | mutex_unlock(&hyperv_mmio_lock); |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 2149 | |
| 2150 | } |
| 2151 | EXPORT_SYMBOL_GPL(vmbus_free_mmio); |
| 2152 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2153 | static int vmbus_acpi_add(struct acpi_device *device) |
| 2154 | { |
| 2155 | acpi_status result; |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2156 | int ret_val = -ENODEV; |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2157 | struct acpi_device *ancestor; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2158 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 2159 | hv_acpi_dev = device; |
| 2160 | |
K. Y. Srinivasan | 0a4425b | 2011-08-27 11:31:38 -0700 | [diff] [blame] | 2161 | result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2162 | vmbus_walk_resources, NULL); |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2163 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2164 | if (ACPI_FAILURE(result)) |
| 2165 | goto acpi_walk_err; |
| 2166 | /* |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2167 | * Some ancestor of the vmbus acpi device (Gen1 or Gen2 |
| 2168 | * firmware) is the VMOD that has the mmio ranges. Get that. |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2169 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2170 | for (ancestor = device->parent; ancestor; ancestor = ancestor->parent) { |
| 2171 | result = acpi_walk_resources(ancestor->handle, METHOD_NAME__CRS, |
| 2172 | vmbus_walk_resources, NULL); |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2173 | |
| 2174 | if (ACPI_FAILURE(result)) |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2175 | continue; |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 2176 | if (hyperv_mmio) { |
| 2177 | vmbus_reserve_fb(); |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2178 | break; |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 2179 | } |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2180 | } |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2181 | ret_val = 0; |
| 2182 | |
| 2183 | acpi_walk_err: |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2184 | complete(&probe_event); |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2185 | if (ret_val) |
| 2186 | vmbus_acpi_remove(device); |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2187 | return ret_val; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
Dexuan Cui | 83b50f8 | 2019-09-19 21:46:12 +0000 | [diff] [blame] | 2190 | #ifdef CONFIG_PM_SLEEP |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2191 | static int vmbus_bus_suspend(struct device *dev) |
| 2192 | { |
Dexuan Cui | b307b38 | 2019-09-05 23:01:21 +0000 | [diff] [blame] | 2193 | struct vmbus_channel *channel, *sc; |
| 2194 | unsigned long flags; |
Dexuan Cui | 1f48dcf | 2019-09-05 23:01:20 +0000 | [diff] [blame] | 2195 | |
| 2196 | while (atomic_read(&vmbus_connection.offer_in_progress) != 0) { |
| 2197 | /* |
| 2198 | * We wait here until the completion of any channel |
| 2199 | * offers that are currently in progress. |
| 2200 | */ |
| 2201 | msleep(1); |
| 2202 | } |
| 2203 | |
| 2204 | mutex_lock(&vmbus_connection.channel_mutex); |
| 2205 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
| 2206 | if (!is_hvsock_channel(channel)) |
| 2207 | continue; |
| 2208 | |
| 2209 | vmbus_force_channel_rescinded(channel); |
| 2210 | } |
| 2211 | mutex_unlock(&vmbus_connection.channel_mutex); |
| 2212 | |
Dexuan Cui | b307b38 | 2019-09-05 23:01:21 +0000 | [diff] [blame] | 2213 | /* |
| 2214 | * Wait until all the sub-channels and hv_sock channels have been |
| 2215 | * cleaned up. Sub-channels should be destroyed upon suspend, otherwise |
| 2216 | * they would conflict with the new sub-channels that will be created |
| 2217 | * in the resume path. hv_sock channels should also be destroyed, but |
| 2218 | * a hv_sock channel of an established hv_sock connection can not be |
| 2219 | * really destroyed since it may still be referenced by the userspace |
| 2220 | * application, so we just force the hv_sock channel to be rescinded |
| 2221 | * by vmbus_force_channel_rescinded(), and the userspace application |
| 2222 | * will thoroughly destroy the channel after hibernation. |
| 2223 | * |
| 2224 | * Note: the counter nr_chan_close_on_suspend may never go above 0 if |
| 2225 | * the VM has no sub-channel and hv_sock channel, e.g. a 1-vCPU VM. |
| 2226 | */ |
| 2227 | if (atomic_read(&vmbus_connection.nr_chan_close_on_suspend) > 0) |
| 2228 | wait_for_completion(&vmbus_connection.ready_for_suspend_event); |
| 2229 | |
Dexuan Cui | d8bd2d4 | 2019-09-05 23:01:22 +0000 | [diff] [blame] | 2230 | WARN_ON(atomic_read(&vmbus_connection.nr_chan_fixup_on_resume) != 0); |
| 2231 | |
Dexuan Cui | b307b38 | 2019-09-05 23:01:21 +0000 | [diff] [blame] | 2232 | mutex_lock(&vmbus_connection.channel_mutex); |
| 2233 | |
| 2234 | list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { |
Dexuan Cui | d8bd2d4 | 2019-09-05 23:01:22 +0000 | [diff] [blame] | 2235 | /* |
| 2236 | * Invalidate the field. Upon resume, vmbus_onoffer() will fix |
| 2237 | * up the field, and the other fields (if necessary). |
| 2238 | */ |
| 2239 | channel->offermsg.child_relid = INVALID_RELID; |
| 2240 | |
Dexuan Cui | b307b38 | 2019-09-05 23:01:21 +0000 | [diff] [blame] | 2241 | if (is_hvsock_channel(channel)) { |
| 2242 | if (!channel->rescind) { |
| 2243 | pr_err("hv_sock channel not rescinded!\n"); |
| 2244 | WARN_ON_ONCE(1); |
| 2245 | } |
| 2246 | continue; |
| 2247 | } |
| 2248 | |
| 2249 | spin_lock_irqsave(&channel->lock, flags); |
| 2250 | list_for_each_entry(sc, &channel->sc_list, sc_list) { |
| 2251 | pr_err("Sub-channel not deleted!\n"); |
| 2252 | WARN_ON_ONCE(1); |
| 2253 | } |
| 2254 | spin_unlock_irqrestore(&channel->lock, flags); |
Dexuan Cui | d8bd2d4 | 2019-09-05 23:01:22 +0000 | [diff] [blame] | 2255 | |
| 2256 | atomic_inc(&vmbus_connection.nr_chan_fixup_on_resume); |
Dexuan Cui | b307b38 | 2019-09-05 23:01:21 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | mutex_unlock(&vmbus_connection.channel_mutex); |
| 2260 | |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2261 | vmbus_initiate_unload(false); |
| 2262 | |
Dexuan Cui | d8bd2d4 | 2019-09-05 23:01:22 +0000 | [diff] [blame] | 2263 | /* Reset the event for the next resume. */ |
| 2264 | reinit_completion(&vmbus_connection.ready_for_resume_event); |
| 2265 | |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2266 | return 0; |
| 2267 | } |
| 2268 | |
| 2269 | static int vmbus_bus_resume(struct device *dev) |
| 2270 | { |
| 2271 | struct vmbus_channel_msginfo *msginfo; |
| 2272 | size_t msgsize; |
| 2273 | int ret; |
| 2274 | |
| 2275 | /* |
| 2276 | * We only use the 'vmbus_proto_version', which was in use before |
| 2277 | * hibernation, to re-negotiate with the host. |
| 2278 | */ |
Andrea Parri | bedc61a | 2019-10-15 13:46:44 +0200 | [diff] [blame] | 2279 | if (!vmbus_proto_version) { |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2280 | pr_err("Invalid proto version = 0x%x\n", vmbus_proto_version); |
| 2281 | return -EINVAL; |
| 2282 | } |
| 2283 | |
| 2284 | msgsize = sizeof(*msginfo) + |
| 2285 | sizeof(struct vmbus_channel_initiate_contact); |
| 2286 | |
| 2287 | msginfo = kzalloc(msgsize, GFP_KERNEL); |
| 2288 | |
| 2289 | if (msginfo == NULL) |
| 2290 | return -ENOMEM; |
| 2291 | |
| 2292 | ret = vmbus_negotiate_version(msginfo, vmbus_proto_version); |
| 2293 | |
| 2294 | kfree(msginfo); |
| 2295 | |
| 2296 | if (ret != 0) |
| 2297 | return ret; |
| 2298 | |
Dexuan Cui | d8bd2d4 | 2019-09-05 23:01:22 +0000 | [diff] [blame] | 2299 | WARN_ON(atomic_read(&vmbus_connection.nr_chan_fixup_on_resume) == 0); |
| 2300 | |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2301 | vmbus_request_offers(); |
| 2302 | |
Dexuan Cui | d8bd2d4 | 2019-09-05 23:01:22 +0000 | [diff] [blame] | 2303 | wait_for_completion(&vmbus_connection.ready_for_resume_event); |
| 2304 | |
Dexuan Cui | b307b38 | 2019-09-05 23:01:21 +0000 | [diff] [blame] | 2305 | /* Reset the event for the next suspend. */ |
| 2306 | reinit_completion(&vmbus_connection.ready_for_suspend_event); |
| 2307 | |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2308 | return 0; |
| 2309 | } |
Dexuan Cui | 83b50f8 | 2019-09-19 21:46:12 +0000 | [diff] [blame] | 2310 | #endif /* CONFIG_PM_SLEEP */ |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2311 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2312 | static const struct acpi_device_id vmbus_acpi_device_ids[] = { |
| 2313 | {"VMBUS", 0}, |
K. Y. Srinivasan | 9d7b18d | 2011-06-06 15:49:42 -0700 | [diff] [blame] | 2314 | {"VMBus", 0}, |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2315 | {"", 0}, |
| 2316 | }; |
| 2317 | MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids); |
| 2318 | |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2319 | /* |
| 2320 | * Note: we must use SET_NOIRQ_SYSTEM_SLEEP_PM_OPS rather than |
| 2321 | * SET_SYSTEM_SLEEP_PM_OPS, otherwise NIC SR-IOV can not work, because the |
| 2322 | * "pci_dev_pm_ops" uses the "noirq" callbacks: in the resume path, the |
| 2323 | * pci "noirq" restore callback runs before "non-noirq" callbacks (see |
| 2324 | * resume_target_kernel() -> dpm_resume_start(), and hibernation_restore() -> |
| 2325 | * dpm_resume_end()). This means vmbus_bus_resume() and the pci-hyperv's |
| 2326 | * resume callback must also run via the "noirq" callbacks. |
| 2327 | */ |
| 2328 | static const struct dev_pm_ops vmbus_bus_pm = { |
| 2329 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(vmbus_bus_suspend, vmbus_bus_resume) |
| 2330 | }; |
| 2331 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2332 | static struct acpi_driver vmbus_acpi_driver = { |
| 2333 | .name = "vmbus", |
| 2334 | .ids = vmbus_acpi_device_ids, |
| 2335 | .ops = { |
| 2336 | .add = vmbus_acpi_add, |
Vitaly Kuznetsov | e4ecb41 | 2015-04-22 21:31:28 -0700 | [diff] [blame] | 2337 | .remove = vmbus_acpi_remove, |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2338 | }, |
Dexuan Cui | f53335e | 2019-09-05 23:01:19 +0000 | [diff] [blame] | 2339 | .drv.pm = &vmbus_bus_pm, |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2340 | }; |
| 2341 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2342 | static void hv_kexec_handler(void) |
| 2343 | { |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 2344 | hv_stimer_global_cleanup(); |
Vitaly Kuznetsov | 75ff3a8 | 2016-02-26 15:13:16 -0800 | [diff] [blame] | 2345 | vmbus_initiate_unload(false); |
Vitaly Kuznetsov | 523b940 | 2016-12-07 14:53:12 -0800 | [diff] [blame] | 2346 | /* Make sure conn_state is set as hv_synic_cleanup checks for it */ |
| 2347 | mb(); |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 2348 | cpuhp_remove_state(hyperv_cpuhp_online); |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 2349 | hyperv_cleanup(); |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2350 | }; |
| 2351 | |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2352 | static void hv_crash_handler(struct pt_regs *regs) |
| 2353 | { |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 2354 | int cpu; |
| 2355 | |
Vitaly Kuznetsov | 75ff3a8 | 2016-02-26 15:13:16 -0800 | [diff] [blame] | 2356 | vmbus_initiate_unload(true); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2357 | /* |
| 2358 | * In crash handler we can't schedule synic cleanup for all CPUs, |
| 2359 | * doing the cleanup for current CPU only. This should be sufficient |
| 2360 | * for kdump. |
| 2361 | */ |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 2362 | cpu = smp_processor_id(); |
| 2363 | hv_stimer_cleanup(cpu); |
Michael Kelley | 7a1323b | 2019-11-14 06:32:01 +0000 | [diff] [blame] | 2364 | hv_synic_disable_regs(cpu); |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 2365 | hyperv_cleanup(); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2366 | }; |
| 2367 | |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame] | 2368 | static int hv_synic_suspend(void) |
| 2369 | { |
| 2370 | /* |
Michael Kelley | 4df4cb9e9 | 2019-11-13 01:11:49 +0000 | [diff] [blame] | 2371 | * When we reach here, all the non-boot CPUs have been offlined. |
| 2372 | * If we're in a legacy configuration where stimer Direct Mode is |
| 2373 | * not enabled, the stimers on the non-boot CPUs have been unbound |
| 2374 | * in hv_synic_cleanup() -> hv_stimer_legacy_cleanup() -> |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame] | 2375 | * hv_stimer_cleanup() -> clockevents_unbind_device(). |
| 2376 | * |
Michael Kelley | 4df4cb9e9 | 2019-11-13 01:11:49 +0000 | [diff] [blame] | 2377 | * hv_synic_suspend() only runs on CPU0 with interrupts disabled. |
| 2378 | * Here we do not call hv_stimer_legacy_cleanup() on CPU0 because: |
| 2379 | * 1) it's unnecessary as interrupts remain disabled between |
| 2380 | * syscore_suspend() and syscore_resume(): see create_image() and |
| 2381 | * resume_target_kernel() |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame] | 2382 | * 2) the stimer on CPU0 is automatically disabled later by |
| 2383 | * syscore_suspend() -> timekeeping_suspend() -> tick_suspend() -> ... |
Michael Kelley | 4df4cb9e9 | 2019-11-13 01:11:49 +0000 | [diff] [blame] | 2384 | * -> clockevents_shutdown() -> ... -> hv_ce_shutdown() |
| 2385 | * 3) a warning would be triggered if we call |
| 2386 | * clockevents_unbind_device(), which may sleep, in an |
| 2387 | * interrupts-disabled context. |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame] | 2388 | */ |
| 2389 | |
| 2390 | hv_synic_disable_regs(0); |
| 2391 | |
| 2392 | return 0; |
| 2393 | } |
| 2394 | |
| 2395 | static void hv_synic_resume(void) |
| 2396 | { |
| 2397 | hv_synic_enable_regs(0); |
| 2398 | |
| 2399 | /* |
| 2400 | * Note: we don't need to call hv_stimer_init(0), because the timer |
| 2401 | * on CPU0 is not unbound in hv_synic_suspend(), and the timer is |
| 2402 | * automatically re-enabled in timekeeping_resume(). |
| 2403 | */ |
| 2404 | } |
| 2405 | |
| 2406 | /* The callbacks run only on CPU0, with irqs_disabled. */ |
| 2407 | static struct syscore_ops hv_synic_syscore_ops = { |
| 2408 | .suspend = hv_synic_suspend, |
| 2409 | .resume = hv_synic_resume, |
| 2410 | }; |
| 2411 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 2412 | static int __init hv_acpi_init(void) |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2413 | { |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2414 | int ret, t; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2415 | |
Michael Kelley | 4a5f3cd | 2017-12-22 11:19:02 -0700 | [diff] [blame] | 2416 | if (!hv_is_hyperv_initialized()) |
Jason Wang | 0592969 | 2012-08-17 18:52:43 +0800 | [diff] [blame] | 2417 | return -ENODEV; |
| 2418 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2419 | init_completion(&probe_event); |
| 2420 | |
| 2421 | /* |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 2422 | * Get ACPI resources first. |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2423 | */ |
K. Y. Srinivasan | 0246604 | 2011-06-06 15:49:40 -0700 | [diff] [blame] | 2424 | ret = acpi_bus_register_driver(&vmbus_acpi_driver); |
| 2425 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2426 | if (ret) |
| 2427 | return ret; |
| 2428 | |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2429 | t = wait_for_completion_timeout(&probe_event, 5*HZ); |
| 2430 | if (t == 0) { |
| 2431 | ret = -ETIMEDOUT; |
| 2432 | goto cleanup; |
| 2433 | } |
Branden Bonaby | af9ca6f | 2019-10-03 17:01:49 -0400 | [diff] [blame] | 2434 | hv_debug_init(); |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2435 | |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 2436 | ret = vmbus_bus_init(); |
K. Y. Srinivasan | 91fd799 | 2011-06-16 13:16:38 -0700 | [diff] [blame] | 2437 | if (ret) |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2438 | goto cleanup; |
| 2439 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2440 | hv_setup_kexec_handler(hv_kexec_handler); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2441 | hv_setup_crash_handler(hv_crash_handler); |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2442 | |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame] | 2443 | register_syscore_ops(&hv_synic_syscore_ops); |
| 2444 | |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2445 | return 0; |
| 2446 | |
| 2447 | cleanup: |
| 2448 | acpi_bus_unregister_driver(&vmbus_acpi_driver); |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 2449 | hv_acpi_dev = NULL; |
K. Y. Srinivasan | 91fd799 | 2011-06-16 13:16:38 -0700 | [diff] [blame] | 2450 | return ret; |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2451 | } |
| 2452 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2453 | static void __exit vmbus_exit(void) |
| 2454 | { |
Vitaly Kuznetsov | e72e7ac | 2015-02-27 11:25:55 -0800 | [diff] [blame] | 2455 | int cpu; |
| 2456 | |
Dexuan Cui | 63ecc6d | 2019-09-05 23:01:16 +0000 | [diff] [blame] | 2457 | unregister_syscore_ops(&hv_synic_syscore_ops); |
| 2458 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2459 | hv_remove_kexec_handler(); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2460 | hv_remove_crash_handler(); |
Vitaly Kuznetsov | 09a1962 | 2015-02-27 11:25:54 -0800 | [diff] [blame] | 2461 | vmbus_connection.conn_state = DISCONNECTED; |
Michael Kelley | fd1fea6 | 2019-07-01 04:25:56 +0000 | [diff] [blame] | 2462 | hv_stimer_global_cleanup(); |
K. Y. Srinivasan | 2db84ef | 2015-04-22 21:31:32 -0700 | [diff] [blame] | 2463 | vmbus_disconnect(); |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 2464 | hv_remove_vmbus_irq(); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2465 | for_each_online_cpu(cpu) { |
| 2466 | struct hv_per_cpu_context *hv_cpu |
| 2467 | = per_cpu_ptr(hv_context.cpu_context, cpu); |
| 2468 | |
| 2469 | tasklet_kill(&hv_cpu->msg_dpc); |
| 2470 | } |
Branden Bonaby | af9ca6f | 2019-10-03 17:01:49 -0400 | [diff] [blame] | 2471 | hv_debug_rm_all_dir(); |
| 2472 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2473 | vmbus_free_channels(); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2474 | |
Denis V. Lunev | cc2dd40 | 2015-08-01 16:08:20 -0700 | [diff] [blame] | 2475 | if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) { |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 2476 | kmsg_dump_unregister(&hv_kmsg_dumper); |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 2477 | unregister_die_notifier(&hyperv_die_block); |
Vitaly Kuznetsov | 096c605 | 2015-04-22 21:31:29 -0700 | [diff] [blame] | 2478 | atomic_notifier_chain_unregister(&panic_notifier_list, |
| 2479 | &hyperv_panic_block); |
| 2480 | } |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 2481 | |
| 2482 | free_page((unsigned long)hv_panic_page); |
Sunil Muthuswamy | 8afc06d | 2018-07-28 21:58:46 +0000 | [diff] [blame] | 2483 | unregister_sysctl_table(hv_ctl_table_hdr); |
| 2484 | hv_ctl_table_hdr = NULL; |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2485 | bus_unregister(&hv_bus); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2486 | |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 2487 | cpuhp_remove_state(hyperv_cpuhp_online); |
Vitaly Kuznetsov | 06210b4 | 2015-08-01 16:08:05 -0700 | [diff] [blame] | 2488 | hv_synic_free(); |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2489 | acpi_bus_unregister_driver(&vmbus_acpi_driver); |
| 2490 | } |
| 2491 | |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2492 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 2493 | MODULE_LICENSE("GPL"); |
Joseph Salisbury | 674eecb | 2019-04-23 03:47:27 +0000 | [diff] [blame] | 2494 | MODULE_DESCRIPTION("Microsoft Hyper-V VMBus Driver"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2495 | |
K. Y. Srinivasan | 43d4e11 | 2011-10-24 11:28:12 -0700 | [diff] [blame] | 2496 | subsys_initcall(hv_acpi_init); |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2497 | module_exit(vmbus_exit); |