Skip to content

Commit 0cf7378

Browse files
vittyvkdavem330
authored andcommitted
hv_netvsc: netvsc_teardown_gpadl() split
It was found that in some cases host refuses to teardown GPADL for send/ receive buffers (probably when some work with these buffere is scheduled or ongoing). Change the teardown logic to be: 1) Send NVSP_MSG1_TYPE_REVOKE_* messages 2) Close the channel 3) Teardown GPADLs. This seems to work reliably. Signed-off-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3928ee6 commit 0cf7378

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

drivers/net/hyperv/netvsc.c

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ static void free_netvsc_device_rcu(struct netvsc_device *nvdev)
100100
call_rcu(&nvdev->rcu, free_netvsc_device);
101101
}
102102

103-
static void netvsc_destroy_buf(struct hv_device *device)
103+
static void netvsc_revoke_buf(struct hv_device *device,
104+
struct netvsc_device *net_device)
104105
{
105106
struct nvsp_message *revoke_packet;
106107
struct net_device *ndev = hv_get_drvdata(device);
107-
struct net_device_context *ndc = netdev_priv(ndev);
108-
struct netvsc_device *net_device = rtnl_dereference(ndc->nvdev);
109108
int ret;
110109

111110
/*
@@ -148,28 +147,6 @@ static void netvsc_destroy_buf(struct hv_device *device)
148147
net_device->recv_section_cnt = 0;
149148
}
150149

151-
/* Teardown the gpadl on the vsp end */
152-
if (net_device->recv_buf_gpadl_handle) {
153-
ret = vmbus_teardown_gpadl(device->channel,
154-
net_device->recv_buf_gpadl_handle);
155-
156-
/* If we failed here, we might as well return and have a leak
157-
* rather than continue and a bugchk
158-
*/
159-
if (ret != 0) {
160-
netdev_err(ndev,
161-
"unable to teardown receive buffer's gpadl\n");
162-
return;
163-
}
164-
net_device->recv_buf_gpadl_handle = 0;
165-
}
166-
167-
if (net_device->recv_buf) {
168-
/* Free up the receive buffer */
169-
vfree(net_device->recv_buf);
170-
net_device->recv_buf = NULL;
171-
}
172-
173150
/* Deal with the send buffer we may have setup.
174151
* If we got a send section size, it means we received a
175152
* NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE msg (ie sent
@@ -210,7 +187,35 @@ static void netvsc_destroy_buf(struct hv_device *device)
210187
}
211188
net_device->send_section_cnt = 0;
212189
}
213-
/* Teardown the gpadl on the vsp end */
190+
}
191+
192+
static void netvsc_teardown_gpadl(struct hv_device *device,
193+
struct netvsc_device *net_device)
194+
{
195+
struct net_device *ndev = hv_get_drvdata(device);
196+
int ret;
197+
198+
if (net_device->recv_buf_gpadl_handle) {
199+
ret = vmbus_teardown_gpadl(device->channel,
200+
net_device->recv_buf_gpadl_handle);
201+
202+
/* If we failed here, we might as well return and have a leak
203+
* rather than continue and a bugchk
204+
*/
205+
if (ret != 0) {
206+
netdev_err(ndev,
207+
"unable to teardown receive buffer's gpadl\n");
208+
return;
209+
}
210+
net_device->recv_buf_gpadl_handle = 0;
211+
}
212+
213+
if (net_device->recv_buf) {
214+
/* Free up the receive buffer */
215+
vfree(net_device->recv_buf);
216+
net_device->recv_buf = NULL;
217+
}
218+
214219
if (net_device->send_buf_gpadl_handle) {
215220
ret = vmbus_teardown_gpadl(device->channel,
216221
net_device->send_buf_gpadl_handle);
@@ -420,7 +425,8 @@ static int netvsc_init_buf(struct hv_device *device,
420425
goto exit;
421426

422427
cleanup:
423-
netvsc_destroy_buf(device);
428+
netvsc_revoke_buf(device, net_device);
429+
netvsc_teardown_gpadl(device, net_device);
424430

425431
exit:
426432
return ret;
@@ -539,11 +545,6 @@ static int netvsc_connect_vsp(struct hv_device *device,
539545
return ret;
540546
}
541547

542-
static void netvsc_disconnect_vsp(struct hv_device *device)
543-
{
544-
netvsc_destroy_buf(device);
545-
}
546-
547548
/*
548549
* netvsc_device_remove - Callback when the root bus device is removed
549550
*/
@@ -557,7 +558,7 @@ void netvsc_device_remove(struct hv_device *device)
557558

558559
cancel_work_sync(&net_device->subchan_work);
559560

560-
netvsc_disconnect_vsp(device);
561+
netvsc_revoke_buf(device, net_device);
561562

562563
RCU_INIT_POINTER(net_device_ctx->nvdev, NULL);
563564

@@ -570,6 +571,8 @@ void netvsc_device_remove(struct hv_device *device)
570571
/* Now, we can close the channel safely */
571572
vmbus_close(device->channel);
572573

574+
netvsc_teardown_gpadl(device, net_device);
575+
573576
/* And dissassociate NAPI context from device */
574577
for (i = 0; i < net_device->num_chn; i++)
575578
netif_napi_del(&net_device->chan_table[i].napi);

0 commit comments

Comments
 (0)