Skip to content

Commit 5362855

Browse files
vittyvkdavem330
authored andcommitted
netvsc: get rid of completion timeouts
I'm hitting 5 second timeout in rndis_filter_set_rss_param() while setting RSS parameters for the device. When this happens we end up returning -ETIMEDOUT from the function and rndis_filter_device_add() falls back to setting net_device->max_chn = 1; net_device->num_chn = 1; net_device->num_sc_offered = 0; but after a moment the rndis request succeeds and subchannels start to appear. netvsc_sc_open() does unconditional nvscdev->num_sc_offered-- and it becomes U32_MAX-1. Consequent rndis_filter_device_remove() will hang while waiting for all U32_MAX-1 subchannels to appear and this is not going to happen. The immediate issue could be solved by adding num_sc_offered > 0 check to netvsc_sc_open() but we're getting out of sync with the host and it's not easy to adjust things later, e.g. in this particular case we'll be creating queues without a user request for it and races are expected. Same applies to other parts of the driver which have the same completion timeout. Following the trend in drivers/hv/* code I suggest we remove all these timeouts completely. As a guest we can always trust the host we're running on and if the host screws things up there is no easy way to recover anyway. Signed-off-by: Vitaly Kuznetsov <[email protected]> Acked-by: Haiyang Zhang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent adba931 commit 5362855

File tree

2 files changed

+31
-100
lines changed

2 files changed

+31
-100
lines changed

drivers/net/hyperv/netvsc.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ static int netvsc_destroy_buf(struct hv_device *device)
244244
static int netvsc_init_buf(struct hv_device *device)
245245
{
246246
int ret = 0;
247-
unsigned long t;
248247
struct netvsc_device *net_device;
249248
struct nvsp_message *init_packet;
250249
struct net_device *ndev;
@@ -305,9 +304,7 @@ static int netvsc_init_buf(struct hv_device *device)
305304
goto cleanup;
306305
}
307306

308-
t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ);
309-
BUG_ON(t == 0);
310-
307+
wait_for_completion(&net_device->channel_init_wait);
311308

312309
/* Check the response */
313310
if (init_packet->msg.v1_msg.
@@ -390,8 +387,7 @@ static int netvsc_init_buf(struct hv_device *device)
390387
goto cleanup;
391388
}
392389

393-
t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ);
394-
BUG_ON(t == 0);
390+
wait_for_completion(&net_device->channel_init_wait);
395391

396392
/* Check the response */
397393
if (init_packet->msg.v1_msg.
@@ -445,7 +441,6 @@ static int negotiate_nvsp_ver(struct hv_device *device,
445441
{
446442
struct net_device *ndev = hv_get_drvdata(device);
447443
int ret;
448-
unsigned long t;
449444

450445
memset(init_packet, 0, sizeof(struct nvsp_message));
451446
init_packet->hdr.msg_type = NVSP_MSG_TYPE_INIT;
@@ -462,10 +457,7 @@ static int negotiate_nvsp_ver(struct hv_device *device,
462457
if (ret != 0)
463458
return ret;
464459

465-
t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ);
466-
467-
if (t == 0)
468-
return -ETIMEDOUT;
460+
wait_for_completion(&net_device->channel_init_wait);
469461

470462
if (init_packet->msg.init_msg.init_complete.status !=
471463
NVSP_STAT_SUCCESS)

drivers/net/hyperv/rndis_filter.c

Lines changed: 28 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
466466
struct rndis_query_request *query;
467467
struct rndis_query_complete *query_complete;
468468
int ret = 0;
469-
unsigned long t;
470469

471470
if (!result)
472471
return -EINVAL;
@@ -503,11 +502,7 @@ static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
503502
if (ret != 0)
504503
goto cleanup;
505504

506-
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
507-
if (t == 0) {
508-
ret = -ETIMEDOUT;
509-
goto cleanup;
510-
}
505+
wait_for_completion(&request->wait_event);
511506

512507
/* Copy the response back */
513508
query_complete = &request->response_msg.msg.query_complete;
@@ -556,7 +551,6 @@ int rndis_filter_set_device_mac(struct net_device *ndev, char *mac)
556551
u32 extlen = sizeof(struct rndis_config_parameter_info) +
557552
2*NWADR_STRLEN + 4*ETH_ALEN;
558553
int ret;
559-
unsigned long t;
560554

561555
request = get_rndis_request(rdev, RNDIS_MSG_SET,
562556
RNDIS_MESSAGE_SIZE(struct rndis_set_request) + extlen);
@@ -597,21 +591,13 @@ int rndis_filter_set_device_mac(struct net_device *ndev, char *mac)
597591
if (ret != 0)
598592
goto cleanup;
599593

600-
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
601-
if (t == 0) {
602-
netdev_err(ndev, "timeout before we got a set response...\n");
603-
/*
604-
* can't put_rndis_request, since we may still receive a
605-
* send-completion.
606-
*/
607-
return -EBUSY;
608-
} else {
609-
set_complete = &request->response_msg.msg.set_complete;
610-
if (set_complete->status != RNDIS_STATUS_SUCCESS) {
611-
netdev_err(ndev, "Fail to set MAC on host side:0x%x\n",
612-
set_complete->status);
613-
ret = -EINVAL;
614-
}
594+
wait_for_completion(&request->wait_event);
595+
596+
set_complete = &request->response_msg.msg.set_complete;
597+
if (set_complete->status != RNDIS_STATUS_SUCCESS) {
598+
netdev_err(ndev, "Fail to set MAC on host side:0x%x\n",
599+
set_complete->status);
600+
ret = -EINVAL;
615601
}
616602

617603
cleanup:
@@ -631,7 +617,6 @@ rndis_filter_set_offload_params(struct net_device *ndev,
631617
struct rndis_set_complete *set_complete;
632618
u32 extlen = sizeof(struct ndis_offload_params);
633619
int ret;
634-
unsigned long t;
635620
u32 vsp_version = nvdev->nvsp_version;
636621

637622
if (vsp_version <= NVSP_PROTOCOL_VERSION_4) {
@@ -665,20 +650,12 @@ rndis_filter_set_offload_params(struct net_device *ndev,
665650
if (ret != 0)
666651
goto cleanup;
667652

668-
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
669-
if (t == 0) {
670-
netdev_err(ndev, "timeout before we got aOFFLOAD set response...\n");
671-
/* can't put_rndis_request, since we may still receive a
672-
* send-completion.
673-
*/
674-
return -EBUSY;
675-
} else {
676-
set_complete = &request->response_msg.msg.set_complete;
677-
if (set_complete->status != RNDIS_STATUS_SUCCESS) {
678-
netdev_err(ndev, "Fail to set offload on host side:0x%x\n",
679-
set_complete->status);
680-
ret = -EINVAL;
681-
}
653+
wait_for_completion(&request->wait_event);
654+
set_complete = &request->response_msg.msg.set_complete;
655+
if (set_complete->status != RNDIS_STATUS_SUCCESS) {
656+
netdev_err(ndev, "Fail to set offload on host side:0x%x\n",
657+
set_complete->status);
658+
ret = -EINVAL;
682659
}
683660

684661
cleanup:
@@ -706,7 +683,6 @@ static int rndis_filter_set_rss_param(struct rndis_device *rdev, int num_queue)
706683
u32 *itab;
707684
u8 *keyp;
708685
int i, ret;
709-
unsigned long t;
710686

711687
request = get_rndis_request(
712688
rdev, RNDIS_MSG_SET,
@@ -749,20 +725,12 @@ static int rndis_filter_set_rss_param(struct rndis_device *rdev, int num_queue)
749725
if (ret != 0)
750726
goto cleanup;
751727

752-
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
753-
if (t == 0) {
754-
netdev_err(ndev, "timeout before we got a set response...\n");
755-
/* can't put_rndis_request, since we may still receive a
756-
* send-completion.
757-
*/
758-
return -ETIMEDOUT;
759-
} else {
760-
set_complete = &request->response_msg.msg.set_complete;
761-
if (set_complete->status != RNDIS_STATUS_SUCCESS) {
762-
netdev_err(ndev, "Fail to set RSS parameters:0x%x\n",
763-
set_complete->status);
764-
ret = -EINVAL;
765-
}
728+
wait_for_completion(&request->wait_event);
729+
set_complete = &request->response_msg.msg.set_complete;
730+
if (set_complete->status != RNDIS_STATUS_SUCCESS) {
731+
netdev_err(ndev, "Fail to set RSS parameters:0x%x\n",
732+
set_complete->status);
733+
ret = -EINVAL;
766734
}
767735

768736
cleanup:
@@ -791,8 +759,6 @@ int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter)
791759
struct rndis_set_complete *set_complete;
792760
u32 status;
793761
int ret;
794-
unsigned long t;
795-
struct net_device *ndev = dev->ndev;
796762

797763
request = get_rndis_request(dev, RNDIS_MSG_SET,
798764
RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
@@ -815,26 +781,14 @@ int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter)
815781
if (ret != 0)
816782
goto cleanup;
817783

818-
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
784+
wait_for_completion(&request->wait_event);
819785

820-
if (t == 0) {
821-
netdev_err(ndev,
822-
"timeout before we got a set response...\n");
823-
ret = -ETIMEDOUT;
824-
/*
825-
* We can't deallocate the request since we may still receive a
826-
* send completion for it.
827-
*/
828-
goto exit;
829-
} else {
830-
set_complete = &request->response_msg.msg.set_complete;
831-
status = set_complete->status;
832-
}
786+
set_complete = &request->response_msg.msg.set_complete;
787+
status = set_complete->status;
833788

834789
cleanup:
835790
if (request)
836791
put_rndis_request(dev, request);
837-
exit:
838792
return ret;
839793
}
840794

@@ -846,7 +800,6 @@ static int rndis_filter_init_device(struct rndis_device *dev)
846800
struct rndis_initialize_complete *init_complete;
847801
u32 status;
848802
int ret;
849-
unsigned long t;
850803
struct netvsc_device *nvdev = net_device_to_netvsc_device(dev->ndev);
851804

852805
request = get_rndis_request(dev, RNDIS_MSG_INIT,
@@ -870,12 +823,7 @@ static int rndis_filter_init_device(struct rndis_device *dev)
870823
goto cleanup;
871824
}
872825

873-
t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
874-
875-
if (t == 0) {
876-
ret = -ETIMEDOUT;
877-
goto cleanup;
878-
}
826+
wait_for_completion(&request->wait_event);
879827

880828
init_complete = &request->response_msg.msg.init_complete;
881829
status = init_complete->status;
@@ -1008,7 +956,6 @@ int rndis_filter_device_add(struct hv_device *dev,
1008956
struct netvsc_device_info *device_info = additional_info;
1009957
struct ndis_offload_params offloads;
1010958
struct nvsp_message *init_packet;
1011-
unsigned long t;
1012959
struct ndis_recv_scale_cap rsscap;
1013960
u32 rsscap_size = sizeof(struct ndis_recv_scale_cap);
1014961
u32 mtu, size;
@@ -1151,11 +1098,8 @@ int rndis_filter_device_add(struct hv_device *dev,
11511098
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
11521099
if (ret)
11531100
goto out;
1154-
t = wait_for_completion_timeout(&net_device->channel_init_wait, 5*HZ);
1155-
if (t == 0) {
1156-
ret = -ETIMEDOUT;
1157-
goto out;
1158-
}
1101+
wait_for_completion(&net_device->channel_init_wait);
1102+
11591103
if (init_packet->msg.v5_msg.subchn_comp.status !=
11601104
NVSP_STAT_SUCCESS) {
11611105
ret = -ENODEV;
@@ -1192,17 +1136,12 @@ void rndis_filter_device_remove(struct hv_device *dev)
11921136
{
11931137
struct netvsc_device *net_dev = hv_device_to_netvsc_device(dev);
11941138
struct rndis_device *rndis_dev = net_dev->extension;
1195-
unsigned long t;
11961139

11971140
/* If not all subchannel offers are complete, wait for them until
11981141
* completion to avoid race.
11991142
*/
1200-
while (net_dev->num_sc_offered > 0) {
1201-
t = wait_for_completion_timeout(&net_dev->channel_init_wait,
1202-
10 * HZ);
1203-
if (t == 0)
1204-
WARN(1, "Netvsc: Waiting for sub-channel processing");
1205-
}
1143+
if (net_dev->num_sc_offered > 0)
1144+
wait_for_completion(&net_dev->channel_init_wait);
12061145

12071146
/* Halt and release the rndis device */
12081147
rndis_filter_halt_device(rndis_dev);

0 commit comments

Comments
 (0)