Thomas Gleixner | 3b20eb2 | 2019-05-29 16:57:35 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2 | /* |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 3 | * Copyright (c) 2009, Microsoft Corporation. |
| 4 | * |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 5 | * Authors: |
| 6 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 7 | * Hank Janssen <hjanssen@microsoft.com> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 8 | */ |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 10 | |
Greg Kroah-Hartman | 5654e93 | 2009-07-14 15:08:20 -0700 | [diff] [blame] | 11 | #include <linux/kernel.h> |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 12 | #include <linux/sched.h> |
| 13 | #include <linux/wait.h> |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 14 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 16 | #include <linux/module.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 17 | #include <linux/hyperv.h> |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 18 | #include <linux/uio.h> |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
Michael Kelley | 6ba3417 | 2018-08-02 03:08:24 +0000 | [diff] [blame] | 20 | #include <asm/page.h> |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 21 | |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 22 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 23 | |
K. Y. Srinivasan | e3fe0bb | 2011-02-11 10:00:12 -0800 | [diff] [blame] | 24 | #define NUM_PAGES_SPANNED(addr, len) \ |
| 25 | ((PAGE_ALIGN(addr + len) >> PAGE_SHIFT) - (addr >> PAGE_SHIFT)) |
| 26 | |
Michael Kelley | 6ba3417 | 2018-08-02 03:08:24 +0000 | [diff] [blame] | 27 | static unsigned long virt_to_hvpfn(void *addr) |
| 28 | { |
Dexuan Cui | a9fc434 | 2019-05-07 07:46:55 +0000 | [diff] [blame] | 29 | phys_addr_t paddr; |
Michael Kelley | 6ba3417 | 2018-08-02 03:08:24 +0000 | [diff] [blame] | 30 | |
| 31 | if (is_vmalloc_addr(addr)) |
| 32 | paddr = page_to_phys(vmalloc_to_page(addr)) + |
| 33 | offset_in_page(addr); |
| 34 | else |
| 35 | paddr = __pa(addr); |
| 36 | |
| 37 | return paddr >> PAGE_SHIFT; |
| 38 | } |
| 39 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 40 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 41 | * vmbus_setevent- Trigger an event notification on the specified |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 42 | * channel. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 43 | */ |
K. Y. Srinivasan | 1f6ee4e | 2016-11-06 13:14:17 -0800 | [diff] [blame] | 44 | void vmbus_setevent(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 45 | { |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 46 | struct hv_monitor_page *monitorpage; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 47 | |
Vitaly Kuznetsov | 991f8f1 | 2017-10-29 12:21:16 -0700 | [diff] [blame] | 48 | trace_vmbus_setevent(channel); |
| 49 | |
K. Y. Srinivasan | 3724287 | 2016-07-01 16:26:37 -0700 | [diff] [blame] | 50 | /* |
| 51 | * For channels marked as in "low latency" mode |
| 52 | * bypass the monitor page mechanism. |
| 53 | */ |
Stephen Hemminger | 5c1bec6 | 2017-02-05 17:20:31 -0700 | [diff] [blame] | 54 | if (channel->offermsg.monitor_allocated && !channel->low_latency) { |
| 55 | vmbus_send_interrupt(channel->offermsg.child_relid); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 56 | |
Greg Kroah-Hartman | 8681db4 | 2013-09-13 11:32:55 -0700 | [diff] [blame] | 57 | /* Get the child to parent monitor page */ |
| 58 | monitorpage = vmbus_connection.monitor_pages[1]; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 59 | |
Olaf Hering | 2235658 | 2011-03-21 14:41:37 +0100 | [diff] [blame] | 60 | sync_set_bit(channel->monitor_bit, |
Haiyang Zhang | f6feebe | 2010-11-08 14:04:39 -0800 | [diff] [blame] | 61 | (unsigned long *)&monitorpage->trigger_group |
| 62 | [channel->monitor_grp].pending); |
Bill Pemberton | 7c369f4 | 2009-07-29 17:00:11 -0400 | [diff] [blame] | 63 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 64 | } else { |
K. Y. Srinivasan | 21c3bef | 2012-12-01 06:46:43 -0800 | [diff] [blame] | 65 | vmbus_set_event(channel); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 66 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 67 | } |
K. Y. Srinivasan | 1f6ee4e | 2016-11-06 13:14:17 -0800 | [diff] [blame] | 68 | EXPORT_SYMBOL_GPL(vmbus_setevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 69 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 70 | /* vmbus_free_ring - drop mapping of ring buffer */ |
| 71 | void vmbus_free_ring(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 72 | { |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 73 | hv_ringbuffer_cleanup(&channel->outbound); |
| 74 | hv_ringbuffer_cleanup(&channel->inbound); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 75 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 76 | if (channel->ringbuffer_page) { |
| 77 | __free_pages(channel->ringbuffer_page, |
| 78 | get_order(channel->ringbuffer_pagecount |
| 79 | << PAGE_SHIFT)); |
| 80 | channel->ringbuffer_page = NULL; |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 81 | } |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 82 | } |
| 83 | EXPORT_SYMBOL_GPL(vmbus_free_ring); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 84 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 85 | /* vmbus_alloc_ring - allocate and map pages for ring buffer */ |
| 86 | int vmbus_alloc_ring(struct vmbus_channel *newchannel, |
| 87 | u32 send_size, u32 recv_size) |
| 88 | { |
| 89 | struct page *page; |
| 90 | int order; |
| 91 | |
| 92 | if (send_size % PAGE_SIZE || recv_size % PAGE_SIZE) |
| 93 | return -EINVAL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 94 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 95 | /* Allocate the ring buffer */ |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 96 | order = get_order(send_size + recv_size); |
K. Y. Srinivasan | 294409d | 2015-05-31 21:27:03 -0700 | [diff] [blame] | 97 | page = alloc_pages_node(cpu_to_node(newchannel->target_cpu), |
Stephen Hemminger | 52a42c2 | 2018-09-14 09:10:16 -0700 | [diff] [blame] | 98 | GFP_KERNEL|__GFP_ZERO, order); |
K. Y. Srinivasan | 294409d | 2015-05-31 21:27:03 -0700 | [diff] [blame] | 99 | |
| 100 | if (!page) |
Stephen Hemminger | 52a42c2 | 2018-09-14 09:10:16 -0700 | [diff] [blame] | 101 | page = alloc_pages(GFP_KERNEL|__GFP_ZERO, order); |
K. Y. Srinivasan | df3493e | 2011-02-11 09:59:00 -0800 | [diff] [blame] | 102 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 103 | if (!page) |
| 104 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 105 | |
Stephen Hemminger | 52a42c2 | 2018-09-14 09:10:16 -0700 | [diff] [blame] | 106 | newchannel->ringbuffer_page = page; |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 107 | newchannel->ringbuffer_pagecount = (send_size + recv_size) >> PAGE_SHIFT; |
| 108 | newchannel->ringbuffer_send_offset = send_size >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 109 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | EXPORT_SYMBOL_GPL(vmbus_alloc_ring); |
K. Y. Srinivasan | 72a95cb | 2011-05-10 07:55:21 -0700 | [diff] [blame] | 113 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 114 | static int __vmbus_open(struct vmbus_channel *newchannel, |
| 115 | void *userdata, u32 userdatalen, |
| 116 | void (*onchannelcallback)(void *context), void *context) |
| 117 | { |
| 118 | struct vmbus_channel_open_channel *open_msg; |
| 119 | struct vmbus_channel_msginfo *open_info = NULL; |
| 120 | struct page *page = newchannel->ringbuffer_page; |
| 121 | u32 send_pages, recv_pages; |
| 122 | unsigned long flags; |
| 123 | int err; |
| 124 | |
| 125 | if (userdatalen > MAX_USER_DEFINED_BYTES) |
| 126 | return -EINVAL; |
| 127 | |
| 128 | send_pages = newchannel->ringbuffer_send_offset; |
| 129 | recv_pages = newchannel->ringbuffer_pagecount - send_pages; |
| 130 | |
| 131 | spin_lock_irqsave(&newchannel->lock, flags); |
| 132 | if (newchannel->state != CHANNEL_OPEN_STATE) { |
| 133 | spin_unlock_irqrestore(&newchannel->lock, flags); |
| 134 | return -EINVAL; |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 135 | } |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 136 | spin_unlock_irqrestore(&newchannel->lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 137 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 138 | newchannel->state = CHANNEL_OPENING_STATE; |
| 139 | newchannel->onchannel_callback = onchannelcallback; |
| 140 | newchannel->channel_callback_context = context; |
Bill Pemberton | 3324fb4 | 2010-05-05 15:27:49 -0400 | [diff] [blame] | 141 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 142 | err = hv_ringbuffer_init(&newchannel->outbound, page, send_pages); |
| 143 | if (err) |
| 144 | goto error_clean_ring; |
| 145 | |
| 146 | err = hv_ringbuffer_init(&newchannel->inbound, |
| 147 | &page[send_pages], recv_pages); |
| 148 | if (err) |
| 149 | goto error_clean_ring; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 150 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 151 | /* Establish the gpadl for the ring buffer */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 152 | newchannel->ringbuffer_gpadlhandle = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 153 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 154 | err = vmbus_establish_gpadl(newchannel, |
| 155 | page_address(newchannel->ringbuffer_page), |
| 156 | (send_pages + recv_pages) << PAGE_SHIFT, |
Vitaly Kuznetsov | 9988ce6 | 2016-09-02 05:58:20 -0700 | [diff] [blame] | 157 | &newchannel->ringbuffer_gpadlhandle); |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 158 | if (err) |
| 159 | goto error_clean_ring; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 160 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 161 | /* Create and init the channel open message */ |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 162 | open_info = kmalloc(sizeof(*open_info) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 163 | sizeof(struct vmbus_channel_open_channel), |
| 164 | GFP_KERNEL); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 165 | if (!open_info) { |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 166 | err = -ENOMEM; |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 167 | goto error_free_gpadl; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 168 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 169 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 170 | init_completion(&open_info->waitevent); |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 171 | open_info->waiting_channel = newchannel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 172 | |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 173 | open_msg = (struct vmbus_channel_open_channel *)open_info->msg; |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 174 | open_msg->header.msgtype = CHANNELMSG_OPENCHANNEL; |
| 175 | open_msg->openid = newchannel->offermsg.child_relid; |
| 176 | open_msg->child_relid = newchannel->offermsg.child_relid; |
| 177 | open_msg->ringbuffer_gpadlhandle = newchannel->ringbuffer_gpadlhandle; |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 178 | open_msg->downstream_ringbuffer_pageoffset = newchannel->ringbuffer_send_offset; |
K. Y. Srinivasan | abbf3b2 | 2012-12-01 06:46:48 -0800 | [diff] [blame] | 179 | open_msg->target_vp = newchannel->target_vp; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 180 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 181 | if (userdatalen) |
K. Y. Srinivasan | 0987ff6 | 2011-08-25 09:48:55 -0700 | [diff] [blame] | 182 | memcpy(open_msg->userdata, userdata, userdatalen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 183 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 184 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 185 | list_add_tail(&open_info->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 186 | &vmbus_connection.chn_msg_list); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 187 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 188 | |
K. Y. Srinivasan | 6f3d791 | 2017-08-11 10:03:59 -0700 | [diff] [blame] | 189 | if (newchannel->rescind) { |
| 190 | err = -ENODEV; |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 191 | goto error_free_info; |
K. Y. Srinivasan | 6f3d791 | 2017-08-11 10:03:59 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 194 | err = vmbus_post_msg(open_msg, |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 195 | sizeof(struct vmbus_channel_open_channel), true); |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 196 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 197 | trace_vmbus_open(open_msg, err); |
Vitaly Kuznetsov | 9202d77 | 2017-10-29 12:21:09 -0700 | [diff] [blame] | 198 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 199 | if (err != 0) |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 200 | goto error_clean_msglist; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 201 | |
Vitaly Kuznetsov | 396e287 | 2016-06-09 17:08:56 -0700 | [diff] [blame] | 202 | wait_for_completion(&open_info->waitevent); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 203 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 204 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 205 | list_del(&open_info->msglistentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 206 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 207 | |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 208 | if (newchannel->rescind) { |
| 209 | err = -ENODEV; |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 210 | goto error_free_info; |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Vitaly Kuznetsov | ffc151f | 2015-05-06 17:47:40 -0700 | [diff] [blame] | 213 | if (open_info->response.open_result.status) { |
| 214 | err = -EAGAIN; |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 215 | goto error_free_info; |
Vitaly Kuznetsov | ffc151f | 2015-05-06 17:47:40 -0700 | [diff] [blame] | 216 | } |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 217 | |
Vitaly Kuznetsov | ffc151f | 2015-05-06 17:47:40 -0700 | [diff] [blame] | 218 | newchannel->state = CHANNEL_OPENED_STATE; |
K. Y. Srinivasan | 176fb9e | 2011-08-25 09:48:57 -0700 | [diff] [blame] | 219 | kfree(open_info); |
Vitaly Kuznetsov | ffc151f | 2015-05-06 17:47:40 -0700 | [diff] [blame] | 220 | return 0; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 221 | |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 222 | error_clean_msglist: |
K. Y. Srinivasan | 1392550 | 2012-10-12 13:22:42 -0700 | [diff] [blame] | 223 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
| 224 | list_del(&open_info->msglistentry); |
| 225 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 226 | error_free_info: |
| 227 | kfree(open_info); |
Vitaly Kuznetsov | 98f531b | 2016-09-02 05:58:19 -0700 | [diff] [blame] | 228 | error_free_gpadl: |
K. Y. Srinivasan | 40384e4 | 2015-02-27 11:26:04 -0800 | [diff] [blame] | 229 | vmbus_teardown_gpadl(newchannel, newchannel->ringbuffer_gpadlhandle); |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 230 | newchannel->ringbuffer_gpadlhandle = 0; |
| 231 | error_clean_ring: |
Vitaly Kuznetsov | 9988ce6 | 2016-09-02 05:58:20 -0700 | [diff] [blame] | 232 | hv_ringbuffer_cleanup(&newchannel->outbound); |
| 233 | hv_ringbuffer_cleanup(&newchannel->inbound); |
Dexuan Cui | ac0d12b | 2015-02-27 11:26:00 -0800 | [diff] [blame] | 234 | newchannel->state = CHANNEL_OPEN_STATE; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 235 | return err; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 236 | } |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 237 | |
| 238 | /* |
| 239 | * vmbus_connect_ring - Open the channel but reuse ring buffer |
| 240 | */ |
| 241 | int vmbus_connect_ring(struct vmbus_channel *newchannel, |
| 242 | void (*onchannelcallback)(void *context), void *context) |
| 243 | { |
| 244 | return __vmbus_open(newchannel, NULL, 0, onchannelcallback, context); |
| 245 | } |
| 246 | EXPORT_SYMBOL_GPL(vmbus_connect_ring); |
| 247 | |
| 248 | /* |
| 249 | * vmbus_open - Open the specified channel. |
| 250 | */ |
| 251 | int vmbus_open(struct vmbus_channel *newchannel, |
| 252 | u32 send_ringbuffer_size, u32 recv_ringbuffer_size, |
| 253 | void *userdata, u32 userdatalen, |
| 254 | void (*onchannelcallback)(void *context), void *context) |
| 255 | { |
| 256 | int err; |
| 257 | |
| 258 | err = vmbus_alloc_ring(newchannel, send_ringbuffer_size, |
| 259 | recv_ringbuffer_size); |
| 260 | if (err) |
| 261 | return err; |
| 262 | |
| 263 | err = __vmbus_open(newchannel, userdata, userdatalen, |
| 264 | onchannelcallback, context); |
| 265 | if (err) |
| 266 | vmbus_free_ring(newchannel); |
| 267 | |
| 268 | return err; |
| 269 | } |
Greg Kroah-Hartman | 36ceadf | 2010-10-21 09:58:21 -0700 | [diff] [blame] | 270 | EXPORT_SYMBOL_GPL(vmbus_open); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 271 | |
Dexuan Cui | 5c23a1a | 2016-01-27 22:29:40 -0800 | [diff] [blame] | 272 | /* Used for Hyper-V Socket: a guest client's connect() to the host */ |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 273 | int vmbus_send_tl_connect_request(const guid_t *shv_guest_servie_id, |
| 274 | const guid_t *shv_host_servie_id) |
Dexuan Cui | 5c23a1a | 2016-01-27 22:29:40 -0800 | [diff] [blame] | 275 | { |
| 276 | struct vmbus_channel_tl_connect_request conn_msg; |
Vitaly Kuznetsov | 98f31a0 | 2017-10-29 12:21:15 -0700 | [diff] [blame] | 277 | int ret; |
Dexuan Cui | 5c23a1a | 2016-01-27 22:29:40 -0800 | [diff] [blame] | 278 | |
| 279 | memset(&conn_msg, 0, sizeof(conn_msg)); |
| 280 | conn_msg.header.msgtype = CHANNELMSG_TL_CONNECT_REQUEST; |
| 281 | conn_msg.guest_endpoint_id = *shv_guest_servie_id; |
| 282 | conn_msg.host_service_id = *shv_host_servie_id; |
| 283 | |
Vitaly Kuznetsov | 98f31a0 | 2017-10-29 12:21:15 -0700 | [diff] [blame] | 284 | ret = vmbus_post_msg(&conn_msg, sizeof(conn_msg), true); |
| 285 | |
| 286 | trace_vmbus_send_tl_connect_request(&conn_msg, ret); |
| 287 | |
| 288 | return ret; |
Dexuan Cui | 5c23a1a | 2016-01-27 22:29:40 -0800 | [diff] [blame] | 289 | } |
| 290 | EXPORT_SYMBOL_GPL(vmbus_send_tl_connect_request); |
| 291 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 292 | /* |
Andrea Parri (Microsoft) | 7527810 | 2020-04-06 02:15:13 +0200 | [diff] [blame^] | 293 | * Set/change the vCPU (@target_vp) the channel (@child_relid) will interrupt. |
| 294 | * |
| 295 | * CHANNELMSG_MODIFYCHANNEL messages are aynchronous. Also, Hyper-V does not |
| 296 | * ACK such messages. IOW we can't know when the host will stop interrupting |
| 297 | * the "old" vCPU and start interrupting the "new" vCPU for the given channel. |
| 298 | * |
| 299 | * The CHANNELMSG_MODIFYCHANNEL message type is supported since VMBus version |
| 300 | * VERSION_WIN10_V4_1. |
| 301 | */ |
| 302 | int vmbus_send_modifychannel(u32 child_relid, u32 target_vp) |
| 303 | { |
| 304 | struct vmbus_channel_modifychannel conn_msg; |
| 305 | int ret; |
| 306 | |
| 307 | memset(&conn_msg, 0, sizeof(conn_msg)); |
| 308 | conn_msg.header.msgtype = CHANNELMSG_MODIFYCHANNEL; |
| 309 | conn_msg.child_relid = child_relid; |
| 310 | conn_msg.target_vp = target_vp; |
| 311 | |
| 312 | ret = vmbus_post_msg(&conn_msg, sizeof(conn_msg), true); |
| 313 | |
| 314 | trace_vmbus_send_modifychannel(&conn_msg, ret); |
| 315 | |
| 316 | return ret; |
| 317 | } |
| 318 | EXPORT_SYMBOL_GPL(vmbus_send_modifychannel); |
| 319 | |
| 320 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 321 | * create_gpadl_header - Creates a gpadl for the specified buffer |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 322 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 323 | static int create_gpadl_header(void *kbuffer, u32 size, |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 324 | struct vmbus_channel_msginfo **msginfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 325 | { |
| 326 | int i; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 327 | int pagecount; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 328 | struct vmbus_channel_gpadl_header *gpadl_header; |
| 329 | struct vmbus_channel_gpadl_body *gpadl_body; |
| 330 | struct vmbus_channel_msginfo *msgheader; |
| 331 | struct vmbus_channel_msginfo *msgbody = NULL; |
| 332 | u32 msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 333 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 334 | int pfnsum, pfncount, pfnleft, pfncurr, pfnsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 335 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 336 | pagecount = size >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 337 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 338 | /* do we need a gpadl body msg */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 339 | pfnsize = MAX_SIZE_CHANNEL_MESSAGE - |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 340 | sizeof(struct vmbus_channel_gpadl_header) - |
| 341 | sizeof(struct gpa_range); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 342 | pfncount = pfnsize / sizeof(u64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 343 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 344 | if (pagecount > pfncount) { |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 345 | /* we need a gpadl body */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 346 | /* fill in the header */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 347 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 348 | sizeof(struct vmbus_channel_gpadl_header) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 349 | sizeof(struct gpa_range) + pfncount * sizeof(u64); |
| 350 | msgheader = kzalloc(msgsize, GFP_KERNEL); |
| 351 | if (!msgheader) |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 352 | goto nomem; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 353 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 354 | INIT_LIST_HEAD(&msgheader->submsglist); |
| 355 | msgheader->msgsize = msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 356 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 357 | gpadl_header = (struct vmbus_channel_gpadl_header *) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 358 | msgheader->msg; |
| 359 | gpadl_header->rangecount = 1; |
| 360 | gpadl_header->range_buflen = sizeof(struct gpa_range) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 361 | pagecount * sizeof(u64); |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 362 | gpadl_header->range[0].byte_offset = 0; |
| 363 | gpadl_header->range[0].byte_count = size; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 364 | for (i = 0; i < pfncount; i++) |
Michael Kelley | 6ba3417 | 2018-08-02 03:08:24 +0000 | [diff] [blame] | 365 | gpadl_header->range[0].pfn_array[i] = virt_to_hvpfn( |
| 366 | kbuffer + PAGE_SIZE * i); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 367 | *msginfo = msgheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 368 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 369 | pfnsum = pfncount; |
| 370 | pfnleft = pagecount - pfncount; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 371 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 372 | /* how many pfns can we fit */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 373 | pfnsize = MAX_SIZE_CHANNEL_MESSAGE - |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 374 | sizeof(struct vmbus_channel_gpadl_body); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 375 | pfncount = pfnsize / sizeof(u64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 376 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 377 | /* fill in the body */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 378 | while (pfnleft) { |
| 379 | if (pfnleft > pfncount) |
| 380 | pfncurr = pfncount; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 381 | else |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 382 | pfncurr = pfnleft; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 383 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 384 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 385 | sizeof(struct vmbus_channel_gpadl_body) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 386 | pfncurr * sizeof(u64); |
| 387 | msgbody = kzalloc(msgsize, GFP_KERNEL); |
K. Y. Srinivasan | f38cf9c | 2011-06-06 15:50:06 -0700 | [diff] [blame] | 388 | |
| 389 | if (!msgbody) { |
| 390 | struct vmbus_channel_msginfo *pos = NULL; |
| 391 | struct vmbus_channel_msginfo *tmp = NULL; |
| 392 | /* |
| 393 | * Free up all the allocated messages. |
| 394 | */ |
| 395 | list_for_each_entry_safe(pos, tmp, |
| 396 | &msgheader->submsglist, |
| 397 | msglistentry) { |
| 398 | |
| 399 | list_del(&pos->msglistentry); |
| 400 | kfree(pos); |
| 401 | } |
| 402 | |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 403 | goto nomem; |
K. Y. Srinivasan | f38cf9c | 2011-06-06 15:50:06 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 406 | msgbody->msgsize = msgsize; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 407 | gpadl_body = |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 408 | (struct vmbus_channel_gpadl_body *)msgbody->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 409 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 410 | /* |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 411 | * Gpadl is u32 and we are using a pointer which could |
| 412 | * be 64-bit |
K. Y. Srinivasan | f27df64 | 2011-06-06 15:49:56 -0700 | [diff] [blame] | 413 | * This is governed by the guest/host protocol and |
Stephen Hemminger | bdc1dd4 | 2017-03-04 18:27:14 -0700 | [diff] [blame] | 414 | * so the hypervisor guarantees that this is ok. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 415 | */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 416 | for (i = 0; i < pfncurr; i++) |
Michael Kelley | 6ba3417 | 2018-08-02 03:08:24 +0000 | [diff] [blame] | 417 | gpadl_body->pfn[i] = virt_to_hvpfn( |
| 418 | kbuffer + PAGE_SIZE * (pfnsum + i)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 419 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 420 | /* add to msg header */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 421 | list_add_tail(&msgbody->msglistentry, |
| 422 | &msgheader->submsglist); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 423 | pfnsum += pfncurr; |
| 424 | pfnleft -= pfncurr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 425 | } |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 426 | } else { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 427 | /* everything fits in a header */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 428 | msgsize = sizeof(struct vmbus_channel_msginfo) + |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 429 | sizeof(struct vmbus_channel_gpadl_header) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 430 | sizeof(struct gpa_range) + pagecount * sizeof(u64); |
| 431 | msgheader = kzalloc(msgsize, GFP_KERNEL); |
| 432 | if (msgheader == NULL) |
Kulikov Vasiliy | e3eb7cd | 2010-07-16 20:13:51 +0400 | [diff] [blame] | 433 | goto nomem; |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 434 | |
| 435 | INIT_LIST_HEAD(&msgheader->submsglist); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 436 | msgheader->msgsize = msgsize; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 437 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 438 | gpadl_header = (struct vmbus_channel_gpadl_header *) |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 439 | msgheader->msg; |
| 440 | gpadl_header->rangecount = 1; |
| 441 | gpadl_header->range_buflen = sizeof(struct gpa_range) + |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 442 | pagecount * sizeof(u64); |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 443 | gpadl_header->range[0].byte_offset = 0; |
| 444 | gpadl_header->range[0].byte_count = size; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 445 | for (i = 0; i < pagecount; i++) |
Michael Kelley | 6ba3417 | 2018-08-02 03:08:24 +0000 | [diff] [blame] | 446 | gpadl_header->range[0].pfn_array[i] = virt_to_hvpfn( |
| 447 | kbuffer + PAGE_SIZE * i); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 448 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 449 | *msginfo = msgheader; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | return 0; |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 453 | nomem: |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 454 | kfree(msgheader); |
| 455 | kfree(msgbody); |
Bill Pemberton | d1c250b | 2010-05-05 15:27:35 -0400 | [diff] [blame] | 456 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 459 | /* |
Stephen Hemminger | bdc1dd4 | 2017-03-04 18:27:14 -0700 | [diff] [blame] | 460 | * vmbus_establish_gpadl - Establish a GPADL for the specified buffer |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 461 | * |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 462 | * @channel: a channel |
Haiyang Zhang | b679ef7 | 2014-01-27 15:03:42 -0800 | [diff] [blame] | 463 | * @kbuffer: from kmalloc or vmalloc |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 464 | * @size: page-size multiple |
| 465 | * @gpadl_handle: some funky thing |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 466 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 467 | int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 468 | u32 size, u32 *gpadl_handle) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 469 | { |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 470 | struct vmbus_channel_gpadl_header *gpadlmsg; |
| 471 | struct vmbus_channel_gpadl_body *gpadl_body; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 472 | struct vmbus_channel_msginfo *msginfo = NULL; |
Vitaly Kuznetsov | 7cc80c9 | 2016-06-03 17:09:24 -0700 | [diff] [blame] | 473 | struct vmbus_channel_msginfo *submsginfo, *tmp; |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 474 | struct list_head *curr; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 475 | u32 next_gpadl_handle; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 476 | unsigned long flags; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 477 | int ret = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 478 | |
K. Y. Srinivasan | 9f52a16 | 2015-01-09 23:54:33 -0800 | [diff] [blame] | 479 | next_gpadl_handle = |
| 480 | (atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 481 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 482 | ret = create_gpadl_header(kbuffer, size, &msginfo); |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 483 | if (ret) |
| 484 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 485 | |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 486 | init_completion(&msginfo->waitevent); |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 487 | msginfo->waiting_channel = channel; |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 488 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 489 | gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->msg; |
| 490 | gpadlmsg->header.msgtype = CHANNELMSG_GPADL_HEADER; |
| 491 | gpadlmsg->child_relid = channel->offermsg.child_relid; |
| 492 | gpadlmsg->gpadl = next_gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 493 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 494 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 495 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 496 | list_add_tail(&msginfo->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 497 | &vmbus_connection.chn_msg_list); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 498 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 499 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 500 | |
K. Y. Srinivasan | 6f3d791 | 2017-08-11 10:03:59 -0700 | [diff] [blame] | 501 | if (channel->rescind) { |
| 502 | ret = -ENODEV; |
| 503 | goto cleanup; |
| 504 | } |
| 505 | |
Haiyang Zhang | c697767 | 2011-01-26 12:12:08 -0800 | [diff] [blame] | 506 | ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize - |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 507 | sizeof(*msginfo), true); |
Vitaly Kuznetsov | 69edbd5 | 2017-10-29 12:21:11 -0700 | [diff] [blame] | 508 | |
| 509 | trace_vmbus_establish_gpadl_header(gpadlmsg, ret); |
| 510 | |
Hank Janssen | 98e0870 | 2011-03-29 13:58:44 -0700 | [diff] [blame] | 511 | if (ret != 0) |
K. Y. Srinivasan | 00d760b | 2011-06-06 15:50:12 -0700 | [diff] [blame] | 512 | goto cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 513 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 514 | list_for_each(curr, &msginfo->submsglist) { |
| 515 | submsginfo = (struct vmbus_channel_msginfo *)curr; |
| 516 | gpadl_body = |
| 517 | (struct vmbus_channel_gpadl_body *)submsginfo->msg; |
Bill Pemberton | 53af545 | 2009-09-11 21:46:44 -0400 | [diff] [blame] | 518 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 519 | gpadl_body->header.msgtype = |
| 520 | CHANNELMSG_GPADL_BODY; |
| 521 | gpadl_body->gpadl = next_gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 522 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 523 | ret = vmbus_post_msg(gpadl_body, |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 524 | submsginfo->msgsize - sizeof(*submsginfo), |
| 525 | true); |
Vitaly Kuznetsov | 69edbd5 | 2017-10-29 12:21:11 -0700 | [diff] [blame] | 526 | |
| 527 | trace_vmbus_establish_gpadl_body(gpadl_body, ret); |
| 528 | |
Vitaly Kuznetsov | 4d63763 | 2016-06-03 17:09:23 -0700 | [diff] [blame] | 529 | if (ret != 0) |
| 530 | goto cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 531 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 532 | } |
K. Y. Srinivasan | 72c6b71 | 2014-08-27 16:25:34 -0700 | [diff] [blame] | 533 | wait_for_completion(&msginfo->waitevent); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 534 | |
Dexuan Cui | eceb059 | 2018-11-26 02:29:56 +0000 | [diff] [blame] | 535 | if (msginfo->response.gpadl_created.creation_status != 0) { |
| 536 | pr_err("Failed to establish GPADL: err = 0x%x\n", |
| 537 | msginfo->response.gpadl_created.creation_status); |
| 538 | |
| 539 | ret = -EDQUOT; |
| 540 | goto cleanup; |
| 541 | } |
| 542 | |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 543 | if (channel->rescind) { |
| 544 | ret = -ENODEV; |
| 545 | goto cleanup; |
| 546 | } |
| 547 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 548 | /* At this point, we received the gpadl created msg */ |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 549 | *gpadl_handle = gpadlmsg->gpadl; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 550 | |
K. Y. Srinivasan | 00d760b | 2011-06-06 15:50:12 -0700 | [diff] [blame] | 551 | cleanup: |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 552 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 553 | list_del(&msginfo->msglistentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 554 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Vitaly Kuznetsov | 7cc80c9 | 2016-06-03 17:09:24 -0700 | [diff] [blame] | 555 | list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist, |
| 556 | msglistentry) { |
| 557 | kfree(submsginfo); |
| 558 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 559 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 560 | kfree(msginfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 561 | return ret; |
| 562 | } |
Greg Kroah-Hartman | 9887372 | 2010-10-21 08:47:43 -0700 | [diff] [blame] | 563 | EXPORT_SYMBOL_GPL(vmbus_establish_gpadl); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 564 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 565 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 566 | * vmbus_teardown_gpadl -Teardown the specified GPADL handle |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 567 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 568 | int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 569 | { |
Greg Kroah-Hartman | 8225021 | 2009-08-26 15:16:04 -0700 | [diff] [blame] | 570 | struct vmbus_channel_gpadl_teardown *msg; |
Greg Kroah-Hartman | aded716 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 571 | struct vmbus_channel_msginfo *info; |
Greg Kroah-Hartman | dd0813b | 2009-07-15 14:56:45 -0700 | [diff] [blame] | 572 | unsigned long flags; |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 573 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 574 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 575 | info = kmalloc(sizeof(*info) + |
| 576 | sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL); |
Bill Pemberton | c3bf2e2 | 2010-05-05 15:27:34 -0400 | [diff] [blame] | 577 | if (!info) |
| 578 | return -ENOMEM; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 579 | |
K. Y. Srinivasan | 9568a19 | 2011-05-10 07:55:39 -0700 | [diff] [blame] | 580 | init_completion(&info->waitevent); |
K. Y. Srinivasan | ccb61f8 | 2016-12-22 16:54:00 -0800 | [diff] [blame] | 581 | info->waiting_channel = channel; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 582 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 583 | msg = (struct vmbus_channel_gpadl_teardown *)info->msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 584 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 585 | msg->header.msgtype = CHANNELMSG_GPADL_TEARDOWN; |
| 586 | msg->child_relid = channel->offermsg.child_relid; |
| 587 | msg->gpadl = gpadl_handle; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 588 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 589 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 590 | list_add_tail(&info->msglistentry, |
Haiyang Zhang | da9fcb7 | 2011-01-26 12:12:14 -0800 | [diff] [blame] | 591 | &vmbus_connection.chn_msg_list); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 592 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
K. Y. Srinivasan | 6f3d791 | 2017-08-11 10:03:59 -0700 | [diff] [blame] | 593 | |
| 594 | if (channel->rescind) |
| 595 | goto post_msg_err; |
| 596 | |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 597 | ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_gpadl_teardown), |
| 598 | true); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 599 | |
Vitaly Kuznetsov | 09cdf8f | 2017-10-29 12:21:12 -0700 | [diff] [blame] | 600 | trace_vmbus_teardown_gpadl(msg, ret); |
| 601 | |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 602 | if (ret) |
| 603 | goto post_msg_err; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 604 | |
K. Y. Srinivasan | 66be653 | 2014-08-27 16:25:32 -0700 | [diff] [blame] | 605 | wait_for_completion(&info->waitevent); |
| 606 | |
| 607 | post_msg_err: |
K. Y. Srinivasan | 5e030d5 | 2017-03-12 20:00:30 -0700 | [diff] [blame] | 608 | /* |
| 609 | * If the channel has been rescinded; |
| 610 | * we will be awakened by the rescind |
| 611 | * handler; set the error code to zero so we don't leak memory. |
| 612 | */ |
| 613 | if (channel->rescind) |
| 614 | ret = 0; |
| 615 | |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 616 | spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 617 | list_del(&info->msglistentry); |
Haiyang Zhang | 15b2f64 | 2011-01-26 12:12:07 -0800 | [diff] [blame] | 618 | spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 619 | |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 620 | kfree(info); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 621 | return ret; |
| 622 | } |
Greg Kroah-Hartman | 18726d7 | 2010-10-21 08:39:59 -0700 | [diff] [blame] | 623 | EXPORT_SYMBOL_GPL(vmbus_teardown_gpadl); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 624 | |
Dexuan Cui | d3b26dd | 2018-08-02 03:08:23 +0000 | [diff] [blame] | 625 | void vmbus_reset_channel_cb(struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 626 | { |
Andrea Parri (Microsoft) | 9403b66 | 2020-04-06 02:15:09 +0200 | [diff] [blame] | 627 | unsigned long flags; |
| 628 | |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 629 | /* |
Dexuan Cui | dad72a1 | 2017-03-04 18:13:58 -0700 | [diff] [blame] | 630 | * vmbus_on_event(), running in the per-channel tasklet, can race |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 631 | * with vmbus_close_internal() in the case of SMP guest, e.g., when |
| 632 | * the former is accessing channel->inbound.ring_buffer, the latter |
Dexuan Cui | dad72a1 | 2017-03-04 18:13:58 -0700 | [diff] [blame] | 633 | * could be freeing the ring_buffer pages, so here we must stop it |
| 634 | * first. |
Andrea Parri (Microsoft) | ac50476 | 2020-04-06 02:15:07 +0200 | [diff] [blame] | 635 | * |
| 636 | * vmbus_chan_sched() might call the netvsc driver callback function |
| 637 | * that ends up scheduling NAPI work that accesses the ring buffer. |
| 638 | * At this point, we have to ensure that any such work is completed |
| 639 | * and that the channel ring buffer is no longer being accessed, cf. |
| 640 | * the calls to napi_disable() in netvsc_device_remove(). |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 641 | */ |
Dexuan Cui | dad72a1 | 2017-03-04 18:13:58 -0700 | [diff] [blame] | 642 | tasklet_disable(&channel->callback_event); |
Dexuan Cui | 63d55b2 | 2015-12-14 16:01:47 -0800 | [diff] [blame] | 643 | |
Andrea Parri (Microsoft) | 9403b66 | 2020-04-06 02:15:09 +0200 | [diff] [blame] | 644 | /* See the inline comments in vmbus_chan_sched(). */ |
| 645 | spin_lock_irqsave(&channel->sched_lock, flags); |
| 646 | channel->onchannel_callback = NULL; |
| 647 | spin_unlock_irqrestore(&channel->sched_lock, flags); |
Dexuan Cui | d3b26dd | 2018-08-02 03:08:23 +0000 | [diff] [blame] | 648 | |
Andrea Parri (Microsoft) | 9403b66 | 2020-04-06 02:15:09 +0200 | [diff] [blame] | 649 | channel->sc_creation_callback = NULL; |
Dexuan Cui | d3b26dd | 2018-08-02 03:08:23 +0000 | [diff] [blame] | 650 | |
| 651 | /* Re-enable tasklet for use on re-open */ |
| 652 | tasklet_enable(&channel->callback_event); |
| 653 | } |
| 654 | |
| 655 | static int vmbus_close_internal(struct vmbus_channel *channel) |
| 656 | { |
| 657 | struct vmbus_channel_close_channel *msg; |
| 658 | int ret; |
| 659 | |
| 660 | vmbus_reset_channel_cb(channel); |
| 661 | |
Dexuan Cui | 64b7faf | 2015-12-14 16:01:48 -0800 | [diff] [blame] | 662 | /* |
| 663 | * In case a device driver's probe() fails (e.g., |
| 664 | * util_probe() -> vmbus_open() returns -ENOMEM) and the device is |
Masahiro Yamada | 8a1115f | 2017-03-09 16:16:31 -0800 | [diff] [blame] | 665 | * rescinded later (e.g., we dynamically disable an Integrated Service |
Dexuan Cui | 64b7faf | 2015-12-14 16:01:48 -0800 | [diff] [blame] | 666 | * in Hyper-V Manager), the driver's remove() invokes vmbus_close(): |
| 667 | * here we should skip most of the below cleanup work. |
| 668 | */ |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 669 | if (channel->state != CHANNEL_OPENED_STATE) |
| 670 | return -EINVAL; |
Dexuan Cui | 64b7faf | 2015-12-14 16:01:48 -0800 | [diff] [blame] | 671 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 672 | channel->state = CHANNEL_OPEN_STATE; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 673 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 674 | /* Send a closing message */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 675 | |
K. Y. Srinivasan | e9a27a9 | 2011-06-06 15:49:59 -0700 | [diff] [blame] | 676 | msg = &channel->close_msg.msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 677 | |
Haiyang Zhang | c50f7fb | 2010-11-08 14:04:38 -0800 | [diff] [blame] | 678 | msg->header.msgtype = CHANNELMSG_CLOSECHANNEL; |
| 679 | msg->child_relid = channel->offermsg.child_relid; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 680 | |
Vitaly Kuznetsov | c0bb039 | 2016-12-07 01:16:24 -0800 | [diff] [blame] | 681 | ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_close_channel), |
| 682 | true); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 683 | |
Vitaly Kuznetsov | 633b005 | 2017-10-29 12:21:10 -0700 | [diff] [blame] | 684 | trace_vmbus_close_internal(msg, ret); |
| 685 | |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 686 | if (ret) { |
| 687 | pr_err("Close failed: close post msg return is %d\n", ret); |
| 688 | /* |
| 689 | * If we failed to post the close msg, |
| 690 | * it is perhaps better to leak memory. |
| 691 | */ |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 694 | /* Tear down the gpadl for the channel's ring buffer */ |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 695 | else if (channel->ringbuffer_gpadlhandle) { |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 696 | ret = vmbus_teardown_gpadl(channel, |
| 697 | channel->ringbuffer_gpadlhandle); |
| 698 | if (ret) { |
| 699 | pr_err("Close failed: teardown gpadl return %d\n", ret); |
| 700 | /* |
| 701 | * If we failed to teardown gpadl, |
| 702 | * it is perhaps better to leak memory. |
| 703 | */ |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 704 | } |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 705 | |
| 706 | channel->ringbuffer_gpadlhandle = 0; |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 707 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 708 | |
K. Y. Srinivasan | 98d731b | 2014-08-27 16:25:33 -0700 | [diff] [blame] | 709 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 710 | } |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 711 | |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 712 | /* disconnect ring - close all channels */ |
| 713 | int vmbus_disconnect_ring(struct vmbus_channel *channel) |
| 714 | { |
| 715 | struct vmbus_channel *cur_channel, *tmp; |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 716 | int ret; |
| 717 | |
| 718 | if (channel->primary_channel != NULL) |
| 719 | return -EINVAL; |
| 720 | |
Dexuan Cui | b5679ce | 2019-01-09 20:56:06 +0000 | [diff] [blame] | 721 | list_for_each_entry_safe(cur_channel, tmp, &channel->sc_list, sc_list) { |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 722 | if (cur_channel->rescind) |
| 723 | wait_for_completion(&cur_channel->rescind_event); |
| 724 | |
| 725 | mutex_lock(&vmbus_connection.channel_mutex); |
| 726 | if (vmbus_close_internal(cur_channel) == 0) { |
| 727 | vmbus_free_ring(cur_channel); |
| 728 | |
| 729 | if (cur_channel->rescind) |
| 730 | hv_process_channel_removal(cur_channel); |
| 731 | } |
| 732 | mutex_unlock(&vmbus_connection.channel_mutex); |
| 733 | } |
| 734 | |
| 735 | /* |
| 736 | * Now close the primary. |
| 737 | */ |
| 738 | mutex_lock(&vmbus_connection.channel_mutex); |
| 739 | ret = vmbus_close_internal(channel); |
| 740 | mutex_unlock(&vmbus_connection.channel_mutex); |
| 741 | |
| 742 | return ret; |
| 743 | } |
| 744 | EXPORT_SYMBOL_GPL(vmbus_disconnect_ring); |
| 745 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 746 | /* |
| 747 | * vmbus_close - Close the specified channel |
| 748 | */ |
| 749 | void vmbus_close(struct vmbus_channel *channel) |
| 750 | { |
Stephen Hemminger | ae6935e | 2018-09-14 09:10:17 -0700 | [diff] [blame] | 751 | if (vmbus_disconnect_ring(channel) == 0) |
| 752 | vmbus_free_ring(channel); |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 753 | } |
Greg Kroah-Hartman | 70bfa30 | 2010-10-21 09:52:22 -0700 | [diff] [blame] | 754 | EXPORT_SYMBOL_GPL(vmbus_close); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 755 | |
stephen hemminger | 5dd0fb9 | 2017-08-16 08:56:26 -0700 | [diff] [blame] | 756 | /** |
| 757 | * vmbus_sendpacket() - Send the specified buffer on the given channel |
Dexuan Cui | fe857bb | 2018-09-23 21:10:41 +0000 | [diff] [blame] | 758 | * @channel: Pointer to vmbus_channel structure |
| 759 | * @buffer: Pointer to the buffer you want to send the data from. |
| 760 | * @bufferlen: Maximum size of what the buffer holds. |
stephen hemminger | 5dd0fb9 | 2017-08-16 08:56:26 -0700 | [diff] [blame] | 761 | * @requestid: Identifier of the request |
Dexuan Cui | fe857bb | 2018-09-23 21:10:41 +0000 | [diff] [blame] | 762 | * @type: Type of packet that is being sent e.g. negotiate, time |
| 763 | * packet etc. |
| 764 | * @flags: 0 or VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED |
stephen hemminger | 5dd0fb9 | 2017-08-16 08:56:26 -0700 | [diff] [blame] | 765 | * |
Dexuan Cui | fe857bb | 2018-09-23 21:10:41 +0000 | [diff] [blame] | 766 | * Sends data in @buffer directly to Hyper-V via the vmbus. |
| 767 | * This will send the data unparsed to Hyper-V. |
stephen hemminger | 5dd0fb9 | 2017-08-16 08:56:26 -0700 | [diff] [blame] | 768 | * |
| 769 | * Mainly used by Hyper-V drivers. |
| 770 | */ |
| 771 | int vmbus_sendpacket(struct vmbus_channel *channel, void *buffer, |
| 772 | u32 bufferlen, u64 requestid, |
| 773 | enum vmbus_packet_type type, u32 flags) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 774 | { |
Greg Kroah-Hartman | 8dc0a06 | 2009-08-27 16:02:36 -0700 | [diff] [blame] | 775 | struct vmpacket_descriptor desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 776 | u32 packetlen = sizeof(struct vmpacket_descriptor) + bufferlen; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 777 | u32 packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 778 | struct kvec bufferlist[3]; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 779 | u64 aligned_data = 0; |
K. Y. Srinivasan | b81658c | 2015-08-01 16:08:14 -0700 | [diff] [blame] | 780 | int num_vecs = ((bufferlen != 0) ? 3 : 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 781 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 782 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 783 | /* Setup the descriptor */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 784 | desc.type = type; /* VmbusPacketTypeDataInBand; */ |
| 785 | desc.flags = flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 786 | /* in 8-bytes granularity */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 787 | desc.offset8 = sizeof(struct vmpacket_descriptor) >> 3; |
| 788 | desc.len8 = (u16)(packetlen_aligned >> 3); |
| 789 | desc.trans_id = requestid; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 790 | |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 791 | bufferlist[0].iov_base = &desc; |
| 792 | bufferlist[0].iov_len = sizeof(struct vmpacket_descriptor); |
| 793 | bufferlist[1].iov_base = buffer; |
| 794 | bufferlist[1].iov_len = bufferlen; |
| 795 | bufferlist[2].iov_base = &aligned_data; |
| 796 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 797 | |
Stephen Hemminger | 5529eaf | 2017-02-11 23:02:22 -0700 | [diff] [blame] | 798 | return hv_ringbuffer_write(channel, bufferlist, num_vecs); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 799 | } |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 800 | EXPORT_SYMBOL(vmbus_sendpacket); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 801 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 802 | /* |
stephen hemminger | 5a668d8 | 2017-08-16 08:56:25 -0700 | [diff] [blame] | 803 | * vmbus_sendpacket_pagebuffer - Send a range of single-page buffer |
K. Y. Srinivasan | 87e93d6 | 2015-02-28 11:39:03 -0800 | [diff] [blame] | 804 | * packets using a GPADL Direct packet type. This interface allows you |
| 805 | * to control notifying the host. This will be useful for sending |
| 806 | * batched data. Also the sender can control the send flags |
| 807 | * explicitly. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 808 | */ |
stephen hemminger | 5a668d8 | 2017-08-16 08:56:25 -0700 | [diff] [blame] | 809 | int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, |
| 810 | struct hv_page_buffer pagebuffers[], |
| 811 | u32 pagecount, void *buffer, u32 bufferlen, |
| 812 | u64 requestid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 813 | { |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 814 | int i; |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 815 | struct vmbus_channel_packet_page_buffer desc; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 816 | u32 descsize; |
| 817 | u32 packetlen; |
| 818 | u32 packetlen_aligned; |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 819 | struct kvec bufferlist[3]; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 820 | u64 aligned_data = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 821 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 822 | if (pagecount > MAX_PAGE_BUFFER_COUNT) |
Bill Pemberton | 002b53e | 2010-05-05 15:27:39 -0400 | [diff] [blame] | 823 | return -EINVAL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 824 | |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 825 | /* |
Haiyang Zhang | 430a8e9 | 2010-09-20 21:07:51 +0000 | [diff] [blame] | 826 | * Adjust the size down since vmbus_channel_packet_page_buffer is the |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 827 | * largest size we support |
| 828 | */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 829 | descsize = sizeof(struct vmbus_channel_packet_page_buffer) - |
| 830 | ((MAX_PAGE_BUFFER_COUNT - pagecount) * |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 831 | sizeof(struct hv_page_buffer)); |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 832 | packetlen = descsize + bufferlen; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 833 | packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 834 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 835 | /* Setup the descriptor */ |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 836 | desc.type = VM_PKT_DATA_USING_GPA_DIRECT; |
stephen hemminger | 5a668d8 | 2017-08-16 08:56:25 -0700 | [diff] [blame] | 837 | desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; |
Stephen Hemminger | bdc1dd4 | 2017-03-04 18:27:14 -0700 | [diff] [blame] | 838 | desc.dataoffset8 = descsize >> 3; /* in 8-bytes granularity */ |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 839 | desc.length8 = (u16)(packetlen_aligned >> 3); |
| 840 | desc.transactionid = requestid; |
Stephen Hemminger | 33d426a | 2017-10-05 17:35:05 -0700 | [diff] [blame] | 841 | desc.reserved = 0; |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 842 | desc.rangecount = pagecount; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 843 | |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 844 | for (i = 0; i < pagecount; i++) { |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 845 | desc.range[i].len = pagebuffers[i].len; |
| 846 | desc.range[i].offset = pagebuffers[i].offset; |
| 847 | desc.range[i].pfn = pagebuffers[i].pfn; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 848 | } |
| 849 | |
K. Y. Srinivasan | 011a7c3 | 2014-02-01 19:02:20 -0800 | [diff] [blame] | 850 | bufferlist[0].iov_base = &desc; |
| 851 | bufferlist[0].iov_len = descsize; |
| 852 | bufferlist[1].iov_base = buffer; |
| 853 | bufferlist[1].iov_len = bufferlen; |
| 854 | bufferlist[2].iov_base = &aligned_data; |
| 855 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 856 | |
Stephen Hemminger | 5529eaf | 2017-02-11 23:02:22 -0700 | [diff] [blame] | 857 | return hv_ringbuffer_write(channel, bufferlist, 3); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 858 | } |
Greg Kroah-Hartman | 713efeb | 2010-10-21 09:29:54 -0700 | [diff] [blame] | 859 | EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 860 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 861 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 862 | * vmbus_sendpacket_multipagebuffer - Send a multi-page buffer packet |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 863 | * using a GPADL Direct packet type. |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 864 | * The buffer includes the vmbus descriptor. |
| 865 | */ |
| 866 | int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel, |
| 867 | struct vmbus_packet_mpb_array *desc, |
| 868 | u32 desc_size, |
| 869 | void *buffer, u32 bufferlen, u64 requestid) |
| 870 | { |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 871 | u32 packetlen; |
| 872 | u32 packetlen_aligned; |
| 873 | struct kvec bufferlist[3]; |
| 874 | u64 aligned_data = 0; |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 875 | |
| 876 | packetlen = desc_size + bufferlen; |
| 877 | packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
| 878 | |
| 879 | /* Setup the descriptor */ |
| 880 | desc->type = VM_PKT_DATA_USING_GPA_DIRECT; |
| 881 | desc->flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; |
Stephen Hemminger | bdc1dd4 | 2017-03-04 18:27:14 -0700 | [diff] [blame] | 882 | desc->dataoffset8 = desc_size >> 3; /* in 8-bytes granularity */ |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 883 | desc->length8 = (u16)(packetlen_aligned >> 3); |
| 884 | desc->transactionid = requestid; |
Stephen Hemminger | 33d426a | 2017-10-05 17:35:05 -0700 | [diff] [blame] | 885 | desc->reserved = 0; |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 886 | desc->rangecount = 1; |
| 887 | |
| 888 | bufferlist[0].iov_base = desc; |
| 889 | bufferlist[0].iov_len = desc_size; |
| 890 | bufferlist[1].iov_base = buffer; |
| 891 | bufferlist[1].iov_len = bufferlen; |
| 892 | bufferlist[2].iov_base = &aligned_data; |
| 893 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); |
| 894 | |
Stephen Hemminger | 5529eaf | 2017-02-11 23:02:22 -0700 | [diff] [blame] | 895 | return hv_ringbuffer_write(channel, bufferlist, 3); |
K. Y. Srinivasan | d61031e | 2015-01-09 23:54:34 -0800 | [diff] [blame] | 896 | } |
| 897 | EXPORT_SYMBOL_GPL(vmbus_sendpacket_mpb_desc); |
| 898 | |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 899 | /** |
Dexuan Cui | fe857bb | 2018-09-23 21:10:41 +0000 | [diff] [blame] | 900 | * __vmbus_recvpacket() - Retrieve the user packet on the specified channel |
| 901 | * @channel: Pointer to vmbus_channel structure |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 902 | * @buffer: Pointer to the buffer you want to receive the data into. |
Dexuan Cui | fe857bb | 2018-09-23 21:10:41 +0000 | [diff] [blame] | 903 | * @bufferlen: Maximum size of what the buffer can hold. |
| 904 | * @buffer_actual_len: The actual size of the data after it was received. |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 905 | * @requestid: Identifier of the request |
Dexuan Cui | fe857bb | 2018-09-23 21:10:41 +0000 | [diff] [blame] | 906 | * @raw: true means keep the vmpacket_descriptor header in the received data. |
Hank Janssen | c88c4e4 | 2010-05-04 15:55:05 -0700 | [diff] [blame] | 907 | * |
| 908 | * Receives directly from the hyper-v vmbus and puts the data it received |
| 909 | * into Buffer. This will receive the data unparsed from hyper-v. |
| 910 | * |
| 911 | * Mainly used by Hyper-V drivers. |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 912 | */ |
Vitaly Kuznetsov | 667d374 | 2015-12-14 19:02:00 -0800 | [diff] [blame] | 913 | static inline int |
| 914 | __vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, |
| 915 | u32 bufferlen, u32 *buffer_actual_len, u64 *requestid, |
| 916 | bool raw) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 917 | { |
K. Y. Srinivasan | 3372592 | 2016-11-06 13:14:18 -0800 | [diff] [blame] | 918 | return hv_ringbuffer_read(channel, buffer, bufferlen, |
| 919 | buffer_actual_len, requestid, raw); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 920 | |
Vitaly Kuznetsov | 667d374 | 2015-12-14 19:02:00 -0800 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, |
| 924 | u32 bufferlen, u32 *buffer_actual_len, |
| 925 | u64 *requestid) |
| 926 | { |
| 927 | return __vmbus_recvpacket(channel, buffer, bufferlen, |
| 928 | buffer_actual_len, requestid, false); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 929 | } |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 930 | EXPORT_SYMBOL(vmbus_recvpacket); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 931 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 932 | /* |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 933 | * vmbus_recvpacket_raw - Retrieve the raw packet on the specified channel |
Greg Kroah-Hartman | f4266e3 | 2009-09-01 17:24:57 -0700 | [diff] [blame] | 934 | */ |
Haiyang Zhang | fff41b2 | 2010-10-07 11:40:08 -0700 | [diff] [blame] | 935 | int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, |
Haiyang Zhang | 39d70a4 | 2010-09-30 10:52:13 -0700 | [diff] [blame] | 936 | u32 bufferlen, u32 *buffer_actual_len, |
| 937 | u64 *requestid) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 938 | { |
Vitaly Kuznetsov | 667d374 | 2015-12-14 19:02:00 -0800 | [diff] [blame] | 939 | return __vmbus_recvpacket(channel, buffer, bufferlen, |
| 940 | buffer_actual_len, requestid, true); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 941 | } |
Greg Kroah-Hartman | adaee6b | 2010-10-21 09:09:23 -0700 | [diff] [blame] | 942 | EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw); |