hv_netvsc: Wait for sub-channels to be processed during probe
Subsystems (3)
PATCH 1/1 hv_netvsc: Wait for sub-channels to be processed during probe
The current code returns from probe without waiting for the proper handling of subchannels that may be requested. If the netvsc driver were to be rapidly loaded/unloaded, we can trigger a panic as the unload will be tearing down state that may not have been fully setup yet. We fix this issue by making sure that we return from the probe call only after ensuring that the sub-channel offers in flight are properly handled.
--- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)
drivers/net/hyperv/hyperv_net.h +2 -0
@@ -671,6 +671,8 @@ struct netvsc_device {u32 send_table[VRSS_SEND_TAB_SIZE ];u32 max_chn;u32 num_chn; +spinlock_t sc_lock;/* Protects num_sc_offered variable */ +u32 num_sc_offered;atomic_t queue_sends[NR_CPUS ];/* Holds rndis device info */
drivers/net/hyperv/rndis_filter.c +25 -0
@@ -984,9 +984,16 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)struct netvsc_device *nvscdev;u16 chn_index = new_sc->offermsg.offer.sub_channel_index;int ret; +unsigned long flags; nvscdev =hv_get_drvdata (new_sc->primary_channel->device_obj); +spin_lock_irqsave (&nvscdev->sc_lock, flags); + nvscdev->num_sc_offered--; +spin_unlock_irqrestore (&nvscdev->sc_lock, flags); +if (nvscdev->num_sc_offered ==0 ) +complete (&nvscdev->channel_init_wait); +if (chn_index >= nvscdev->num_chn)return ;
@@ -1015,8 +1022,10 @@ int rndis_filter_device_add(struct hv_device *dev,u32 rsscap_size =sizeof (struct ndis_recv_scale_cap );u32 mtu, size;u32 num_rss_qs; +u32 sc_delta;const struct cpumask *node_cpu_mask;u32 num_possible_rss_qs; +unsigned long flags; rndis_device =get_rndis_device ();if (!rndis_device)
@@ -1039,6 +1048,8 @@ int rndis_filter_device_add(struct hv_device *dev, net_device->max_chn =1 ; net_device->num_chn =1 ; +spin_lock_init (&net_device->sc_lock); + net_device->extension = rndis_device; rndis_device->net_dev = net_device;
@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device *dev, num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); + num_rss_qs = net_device->num_chn -1 ; + net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;
@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct hv_device *dev, ret =rndis_filter_set_rss_param (rndis_device, net_device->num_chn); +/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); + sc_delta = net_device->num_chn -1 - num_rss_qs; + net_device->num_sc_offered -= sc_delta; +spin_unlock_irqrestore (&net_device->sc_lock, flags); + +if (net_device->num_sc_offered !=0 ) +wait_for_completion (&net_device->channel_init_wait); out:if (ret) { net_device->max_chn =1 ; net_device->num_chn =1 ; } +return 0 ;/* return 0 because primary channel can be used alone */ err_dev_remv:
Signature · 1 line
1.7.4.1
Dexuan Cui
maintainerQuoted 17 lines
From: K. Y. Srinivasan
Sent: Friday, July 17, 2015 3:17
Subject: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probedrivers/net/hyperv/hyperv_net.h +3
-0@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device *dev, num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); + num_rss_qs = net_device->num_chn -1 ; + net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;
drivers/net/hyperv/hyperv_net.h int rndis_filter_device_add(struct hv_device *dev, · line 1179
Quoted 9 lines
drivers/net/hyperv/hyperv_net.h +6
-0@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct hv_device *dev, ret =rndis_filter_set_rss_param (rndis_device, net_device->num_chn); +/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); + sc_delta = net_device->num_chn -1 - num_rss_qs; + net_device->num_sc_offered -= sc_delta;
Hi KY,
IMO here the "-= " should be "+="?
I think sc_delta is usually <= 0, meaning the host may allocate less subchannels than we expect.
With "-=", net_device->num_sc_offered can become bigger -- this doesn't seem correct.
Why not use
"net_device->num_sc_offered = net_device->num_chn - 1;" directly? At this point, net_device->num_chn has been the number of the actual channels.
drivers/net/hyperv/hyperv_net.h int rndis_filter_device_add(struct hv_device *dev, · line 1183
Quoted 4 lines
drivers/net/hyperv/hyperv_net.h +4
-0+spin_unlock_irqrestore (&net_device->sc_lock, flags); + +if (net_device->num_sc_offered !=0 ) +wait_for_completion (&net_device->channel_init_wait);
BTW, I also tested the patch and I can confirm the panic I saw disappeared with the patch.
-- Dexuan
Quoted 47 lines
-----Original Message-----
From: Dexuan Cui
Sent: Friday, July 17, 2015 3:01 AM
To: KY Srinivasan; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: KY Srinivasan
Subject: RE: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probeQuoted 3 lines
From: K. Y. Srinivasan
Sent: Friday, July 17, 2015 3:17
Subject: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to beprocessed
Review
Quoted 2 lines
during probe
(quoted diff) +0
-0
b/drivers/net/hyperv/hyperv_net.hReview int rndis_filter_device_add(struct hv_device
Quoted 2 lines
...
(quoted diff) +0
-0@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +3
-0num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); + num_rss_qs = net_device->num_chn -1 ; + net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1179
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +6
-0ret =rndis_filter_set_rss_param (rndis_device, net_device- num_chn); +/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); + sc_delta = net_device->num_chn -1 - num_rss_qs; + net_device->num_sc_offered -= sc_delta;Hi KY,
IMO here the "-= " should be "+="?
Quoted 5 lines
I think
sc_deltais usually <= 0, meaning the host may allocate less subchannels than
we expect.
With "-=",net_device->num_sc_offeredcan become bigger -- this doesn't seem correct.
We control how many sub-channels we want the host to offer (say sc_requested). Based on this number we begin to track how many have actually been processed - we decrement sc_requested each time a sub-channel offer is processed. If the host were to actually offer all that we have requested, then checking for sc_requested to be zero is sufficient to ensure that we have processed all the potentially in-flight sub-channels. However, the host may choose to offer less than what we had asked for and the variable "delta" is tracking this difference. Since we are counting down from what we had asked for we have to subtract "delta" for proper accounting.
Quoted 5 lines
Why not use
"net_device->num_sc_offered=net_device->num_chn- 1;" directly? At this point,net_device->num_chnhas been the number of the actual channels.
I am not sure what the question here is. num_sc_offered is initialized to the number we are going to ask and this is the number that will be decremented each time a sub-channel is processed. Since the host may decide to offer us less than what we had asked and some sub-channels may have already been processed (num_sc_offerred decremented accordingly) by the time we discover that the host has offered us less than what we asked for, we adjust num_sc_offered accordingly.
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1183
Quoted 6 lines
drivers/net/hyperv/rndis_filter.c +4
-0+spin_unlock_irqrestore (&net_device->sc_lock, flags); + +if (net_device->num_sc_offered !=0 ) +wait_for_completion (&net_device->channel_init_wait);BTW, I also tested the patch and I can confirm the panic I saw disappeared with the patch.
Thank you.
K. Y
Quoted 2 lines
-- Dexuan
Dexuan Cui
maintainerQuoted 44 lines
From: KY Srinivasan
Sent: Friday, July 17, 2015 23:33Quoted 37 lines
From: Dexuan Cui
Sent: Friday, July 17, 2015 3:01 AMQuoted 3 lines
From: K. Y. Srinivasan
Sent: Friday, July 17, 2015 3:17
Subject: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to beprocessed
Review
Quoted 2 lines
during probe
(quoted diff) +0
-0
b/drivers/net/hyperv/hyperv_net.hReview int rndis_filter_device_add(struct hv_device
Quoted 2 lines
...
(quoted diff) +0
-0@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +3
-0num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); +num_rss_qs = net_device->num_chn -1 ; +net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1179
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +6
-0ret =rndis_filter_set_rss_param (rndis_device, net_device- num_chn); +/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); +sc_delta = net_device->num_chn -1 - num_rss_qs; +net_device->num_sc_offered -= sc_delta;Hi KY,
IMO here the "-= " should be "+="?Quoted 5 lines
I think
sc_deltais usually <= 0, meaning the host may allocate less subchannels than
we expect.
With "-=",net_device->num_sc_offeredcan become bigger -- this doesn't seem correct.
Quoted 13 lines
We control how many sub-channels we want the host to offer (say
sc_requested). Based on this
number we begin to track how many have actually been processed - we decrementsc_requested
each time a sub-channel offer is processed. If the host were to actually offer all that we have requested,
then checking forsc_requestedto be zero is sufficient to ensure that we have processed all the
potentially in-flight sub-channels. However, the host may choose to offer less than what we had asked for
and the variable "delta" is tracking this difference. Since we are counting down from what we had asked for
we have to subtract "delta" for proper accounting.
Yes, I understand the rationale.
Let me show the issue by example:
Let's assume sc_requested is 7 and the host actually only offers 3 sub-channels:
1. Just before sending the NVSP_MSG5_TYPE_SUBCHANNEL message, we have net_device->num_chn == 8,num_rss_qs == 7net_device->num_sc_offered == 7
2. Just after we get the reply of the message, net_device->num_chn == 4sc_delta = net_device->num_chn - 1 - num_rss_qs, so sc_delta == 4 - 1 - 7 = -4 net_device->num_sc_offered -= sc_delta, so net_device->num_sc_offered == 7 - (-4) = 11. It's not zero, so we sleep on the wait_for_completion().
3. Now we process the 3 sub-channel and net_device->num_sc_offered will become 11 -1 -1 -1 == 8 and no complete() will be invoked!
That's why I think the "-=" in the linenet_device->num_sc_offered -= sc_delta
should be "+=".
Quoted 5 lines
Quoted 4 lines
Why not use
"net_device->num_sc_offered=net_device->num_chn- 1;" directly? At this point,net_device->num_chnhas been the number of the actual channels.
Quoted 11 lines
I am not sure what the question here is.
num_sc_offeredis initialized to the number we
are going to ask and this is the number that will be decremented each time a sub-channel
is processed. Since the host may decide to offer us less than what we had asked and some
sub-channels may have already been processed (num_sc_offerreddecremented accordingly)
by the time we discover that the host has offered us less than what we asked for, we adjustnum_sc_offeredaccordingly.
Sorry, I had a misunderstanding here.
Please just ignore this question.
Thanks,
-- Dexuan
Quoted 95 lines
-----Original Message-----
From: Dexuan Cui
Sent: Monday, July 20, 2015 2:39 AM
To: KY Srinivasan; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probeQuoted 17 lines
From: KY Srinivasan
Sent: Friday, July 17, 2015 23:33Quoted 15 lines
From: Dexuan Cui
Sent: Friday, July 17, 2015 3:01 AMQuoted 3 lines
From: K. Y. Srinivasan
Sent: Friday, July 17, 2015 3:17
Subject: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to beprocessed
Review
Quoted 2 lines
during probe
(quoted diff) +0
-0
b/drivers/net/hyperv/hyperv_net.hReview int rndis_filter_device_add(struct hv_device
Quoted 2 lines
...
(quoted diff) +0
-0@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device*dev,
Quoted 3 lines
drivers/net/hyperv/rndis_filter.c +0
-0num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs);Quoted 7 lines
Quoted 7 lines
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct
Quoted 7 lines
drivers/net/hyperv/rndis_filter.c +3
-0+num_rss_qs = net_device->num_chn -1 ; +net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct
hv_deviceQuoted 15 lines
Quoted 15 lines
*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1179
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +6
-0ret =rndis_filter_set_rss_param (rndis_device, net_device- num_chn); +/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); +sc_delta = net_device->num_chn -1 - num_rss_qs; +net_device->num_sc_offered -= sc_delta;Hi KY,
IMO here the "-= " should be "+="?Quoted 4 lines
Quoted 4 lines
I think
sc_deltais usually <= 0, meaning the host may allocate less subchannels than
we expect.
With "-=",net_device->num_sc_offeredcan become bigger -- thisdoesn't
Quoted 6 lines
Quoted 1 line
seem correct.
We control how many sub-channels we want the host to offer (say
sc_requested). Based on this
number we begin to track how many have actually been processed - we decrementsc_requested
each time a sub-channel offer is processed. If the host were to actuallyoffer all
Quoted 2 lines
that we have requested,
then checking forsc_requestedto be zero is sufficient to ensure that wehave
Quoted 2 lines
processed all the
potentially in-flight sub-channels. However, the host may choose to offerless
Quoted 2 lines
than what we had asked for
and the variable "delta" is tracking this difference. Since we are countingdown
Quoted 2 lines
from what we had asked for
we have to subtract "delta" for proper accounting.Yes, I understand the rationale.
Let me show the issue by example:Let's assume
sc_requestedis 7 and the host actually only offers 3 sub- channels:
1. Just before sending theNVSP_MSG5_TYPE_SUBCHANNELmessage, we havenet_device->num_chn== 8,num_rss_qs== 7net_device->num_sc_offered== 72. Just after we get the reply of the message,
net_device->num_chn== 4sc_delta=net_device->num_chn- 1 -num_rss_qs, sosc_delta== 4 - 1 - 7 = - 4net_device->num_sc_offered-=sc_delta, sonet_device->num_sc_offered== 7 - (-4) = 11. It's not zero, so we sleep on thewait_for_completion().
Quoted 6 lines
3. Now we process the 3 sub-channel and
net_device->num_sc_offeredwill become 11 -1 -1 -1 == 8 and nocomplete()will be invoked!That's why I think the "-=" in the line
net_device->num_sc_offered-=sc_delta
should be "+=".
Thanks Dexuan; I will fix the issue and resend.
Regards,
K. Y
Dexuan Cui
maintainerQuoted 12 lines
From: K. Y. Srinivasan
Sent: Friday, July 17, 2015 3:17
Subject: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probeThe current code returns from probe without waiting for the proper handling of subchannels that may be requested. If the netvsc driver were to be rapidly loaded/unloaded, we can trigger a panic as the unload will be tearing down state that may not have been fully setup yet. We fix this issue by making sure that we return from the probe call only after ensuring that the sub-channel offers in flight are properly handled.
Quoted 4 lines
--- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)
BTW, not sure if we should make the same fix to storvsc.
IMO storvsc should have the same issue, at least in theory, though usually it's unlikely to unload storvsc. :-)
Thanks,
-- Dexuan
Quoted 33 lines
-----Original Message-----
From: Dexuan Cui
Sent: Friday, July 17, 2015 3:07 AM
To: KY Srinivasan; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: KY Srinivasan
Subject: RE: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probeQuoted 3 lines
From: K. Y. Srinivasan
Sent: Friday, July 17, 2015 3:17
Subject: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to beprocessed
Quoted 3 lines
during probe
The current code returns from probe without waiting for the proper
handling
Quoted 1 line
of subchannels that may be requested. If the netvsc driver were to be
rapidly
Quoted 2 lines
loaded/unloaded, we can trigger a panic as the unload will be tearing down state that may not have been fully setup yet. We fix this issue by
making
Quoted 7 lines
sure that we return from the probe call only after ensuring that the sub-channel offers in flight are properly handled.
--- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)
Quoted 4 lines
BTW, not sure if we should make the same fix to storvsc.
IMO storvsc should have the same issue, at least in theory, though usually it's unlikely to unload storvsc. :-)
You are right; I am planning to submit a similar patch for storvsc. As you note, this scenario is unlikely for sorvsc.
K. Y
Quoted 3 lines
Thanks,
-- Dexuan
Quoted 82 lines · K. Y. Srinivasan
The current code returns from probe without waiting for the proper handling of subchannels that may be requested. If the netvsc driver were to be rapidly loaded/unloaded, we can trigger a panic as the unload will be tearing down state that may not have been fully setup yet. We fix this issue by making sure that we return from the probe call only after ensuring that the sub-channel offers in flight are properly handled.
Signed-off-by K. Y. Srinivasan <[email protected]>Reviewed-and-tested-by Haiyang Zhang <[email protected]--- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)drivers/net/hyperv/hyperv_net.h +2
-0@@ -671,6 +671,8 @@ struct netvsc_device {u32 send_table[VRSS_SEND_TAB_SIZE ];u32 max_chn;u32 num_chn; +spinlock_t sc_lock;/* Protects num_sc_offered variable */ +u32 num_sc_offered;atomic_t queue_sends[NR_CPUS ];/* Holds rndis device info */ drivers/net/hyperv/rndis_filter.c +14
-0@@ -984,9 +984,16 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)struct netvsc_device *nvscdev;u16 chn_index = new_sc->offermsg.offer.sub_channel_index;int ret; +unsigned long flags; nvscdev =hv_get_drvdata (new_sc->primary_channel->device_obj); +spin_lock_irqsave (&nvscdev->sc_lock, flags); + nvscdev->num_sc_offered--; +spin_unlock_irqrestore (&nvscdev->sc_lock, flags); +if (nvscdev->num_sc_offered ==0 ) +complete (&nvscdev->channel_init_wait); +if (chn_index >= nvscdev->num_chn)return ;@@ -1015,8 +1022,10 @@ int rndis_filter_device_add(struct hv_device *dev,u32 rsscap_size =sizeof (struct ndis_recv_scale_cap );u32 mtu, size;u32 num_rss_qs; +u32 sc_delta;const struct cpumask *node_cpu_mask;u32 num_possible_rss_qs; +unsigned long flags; rndis_device =get_rndis_device ();if (!rndis_device)@@ -1039,6 +1048,8 @@ int rndis_filter_device_add(struct hv_device *dev, net_device->max_chn =1 ; net_device->num_chn =1 ; +spin_lock_init (&net_device->sc_lock); + net_device->extension = rndis_device; rndis_device->net_dev = net_device;@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device *dev, num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); + num_rss_qs = net_device->num_chn -1 ; + net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct hv_device *dev, ret =rndis_filter_set_rss_param (rndis_device, net_device->num_chn);
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1183
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +10
-0+/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); + sc_delta = net_device->num_chn -1 - num_rss_qs; + net_device->num_sc_offered -= sc_delta; +spin_unlock_irqrestore (&net_device->sc_lock, flags); + +if (net_device->num_sc_offered !=0 ) +wait_for_completion (&net_device->channel_init_wait);
I'd suggest we add an essentian timeout (big, let's say 30 sec.) here. In case something goes wrong we don't really want to hang the whole kernel for forever. Such bugs are hard to debug as if a 'kernel hangs' is reported we can't be sure which wait caused it. We can even have something like:
t = wait_for_completion_timeout(&net_device->channel_init_wait, 30*HZ); BUG_ON(t == 0);
This is much better as we'll be sure what went wrong. (I know other pieces of hyper-v code use wait_for_completion() without a timeout, this is rather a general suggestion for all of them).
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c +1
-0out:if (ret) { net_device->max_chn =1 ; net_device->num_chn =1 ; } +return 0 ;/* return 0 because primary channel can be used alone */ err_dev_remv:
Signature · 1 line
Vitaly
Quoted 124 lines
-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Friday, July 17, 2015 7:13 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Dexuan Cui
Subject: Re: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probeQuoted 1 line · K. Y. Srinivasan
The current code returns from probe without waiting for the proper
handling
Quoted 1 line
of subchannels that may be requested. If the netvsc driver were to be
rapidly
Quoted 2 lines
loaded/unloaded, we can trigger a panic as the unload will be tearing down state that may not have been fully setup yet. We fix this issue by
making
Review
Quoted 11 lines
sure that we return from the probe call only after ensuring that the sub-channel offers in flight are properly handled.
Signed-off-by K. Y. Srinivasan <[email protected]>Reviewed-and-tested-by Haiyang Zhang <[email protected]--- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/net/hyperv/hyperv_net.hReview
Quoted 13 lines
index 26cd14c..925b75d 100644
drivers/net/hyperv/hyperv_net.h +2
-0@@ -671,6 +671,8 @@ struct netvsc_device {u32 send_table[VRSS_SEND_TAB_SIZE ];u32 max_chn;u32 num_chn; +spinlock_t sc_lock;/* Protects num_sc_offered variable */ +u32 num_sc_offered;atomic_t queue_sends[NR_CPUS ];/* Holds rndis device info */ (quoted diff) +0
-0
b/drivers/net/hyperv/rndis_filter.cdrivers/net/hyperv/rndis_filter.c static void netvsc_sc_open(struct vmbus_channel
Quoted 4 lines
index 2e40417..2e09f3f 100644
drivers/net/hyperv/rndis_filter.c +0
-0@@ -984,9 +984,16 @@ static void netvsc_sc_open(struct vmbus_channel
*new_sc)drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 17 lines
drivers/net/hyperv/rndis_filter.c +7
-0struct netvsc_device *nvscdev;u16 chn_index = new_sc->offermsg.offer.sub_channel_index;int ret; +unsigned long flags; nvscdev =hv_get_drvdata (new_sc->primary_channel->device_obj); +spin_lock_irqsave (&nvscdev->sc_lock, flags); + nvscdev->num_sc_offered--; +spin_unlock_irqrestore (&nvscdev->sc_lock, flags); +if (nvscdev->num_sc_offered ==0 ) +complete (&nvscdev->channel_init_wait); +if (chn_index >= nvscdev->num_chn)return ;@@ -1015,8 +1022,10 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 11 lines
drivers/net/hyperv/rndis_filter.c +2
-0u32 rsscap_size =sizeof (struct ndis_recv_scale_cap );u32 mtu, size;u32 num_rss_qs; +u32 sc_delta;const struct cpumask *node_cpu_mask;u32 num_possible_rss_qs; +unsigned long flags; rndis_device =get_rndis_device ();if (!rndis_device)@@ -1039,6 +1048,8 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c +2
-0net_device->max_chn =1 ; net_device->num_chn =1 ; +spin_lock_init (&net_device->sc_lock); + net_device->extension = rndis_device; rndis_device->net_dev = net_device;@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +3
-0num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); + num_rss_qs = net_device->num_chn -1 ; + net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct hv_device*dev,
Quoted 4 lines
drivers/net/hyperv/rndis_filter.c +0
-0ret =rndis_filter_set_rss_param (rndis_device, net_device- num_chn);drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1183
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +10
-0+/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); + sc_delta = net_device->num_chn -1 - num_rss_qs; + net_device->num_sc_offered -= sc_delta; +spin_unlock_irqrestore (&net_device->sc_lock, flags); + +if (net_device->num_sc_offered !=0 ) +wait_for_completion (&net_device->channel_init_wait);I'd suggest we add an essentian timeout (big, let's say 30 sec.) here. In case something goes wrong we don't really want to hang the whole kernel for forever. Such bugs are hard to debug as if a 'kernel hangs' is reported we can't be sure which wait caused it. We can even have something like:
Quoted 6 lines
t =
wait_for_completion_timeout(&net_device->channel_init_wait, 30*HZ);BUG_ON(t == 0);This is much better as we'll be sure what went wrong. (I know other pieces of hyper-v code use
wait_for_completion()without a timeout, this is rather a general suggestion for all of them).
There is some history here. Initially, I had timeout for calls where we could reasonably rollback state if we timed out. Some calls were subsequently changed to unconditional wait because under some load conditions, these timeouts would trigger (granted I did not have 30 second timeout; it was a 5 second timeout).
Greg was opposed to calls to BUG_ON() in general for drivers. Consequently, I have chosen to wait unconditionally in cases where there is no sensible rollback if we were to timeout (rather thank bug checking).
In this specific case though, we can have a timeout and we don't need to bug check if we timeout.
I will make this change and resubmit.
Thanks,
K. Y
Quoted 13 lines
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1192
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +1
-0out:if (ret) { net_device->max_chn =1 ; net_device->num_chn =1 ; } +return 0 ;/* return 0 because primary channel can be used alone */ err_dev_remv:--
Vitaly
Quoted 129 lines · KY Srinivasan
Quoted 122 lines
-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Friday, July 17, 2015 7:13 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Dexuan Cui
Subject: Re: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probeQuoted 1 line · K. Y. Srinivasan
The current code returns from probe without waiting for the proper
handling
Quoted 1 line
of subchannels that may be requested. If the netvsc driver were to be
rapidly
Quoted 2 lines
loaded/unloaded, we can trigger a panic as the unload will be tearing down state that may not have been fully setup yet. We fix this issue by
making
Review
Quoted 11 lines
sure that we return from the probe call only after ensuring that the sub-channel offers in flight are properly handled.
Signed-off-by K. Y. Srinivasan <[email protected]>Reviewed-and-tested-by Haiyang Zhang <[email protected]--- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/net/hyperv/hyperv_net.hReview
Quoted 13 lines
index 26cd14c..925b75d 100644
drivers/net/hyperv/hyperv_net.h +2
-0@@ -671,6 +671,8 @@ struct netvsc_device {u32 send_table[VRSS_SEND_TAB_SIZE ];u32 max_chn;u32 num_chn; +spinlock_t sc_lock;/* Protects num_sc_offered variable */ +u32 num_sc_offered;atomic_t queue_sends[NR_CPUS ];/* Holds rndis device info */ (quoted diff) +0
-0
b/drivers/net/hyperv/rndis_filter.cdrivers/net/hyperv/rndis_filter.c static void netvsc_sc_open(struct vmbus_channel
Quoted 4 lines
index 2e40417..2e09f3f 100644
drivers/net/hyperv/rndis_filter.c +0
-0@@ -984,9 +984,16 @@ static void netvsc_sc_open(struct vmbus_channel
*new_sc)drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 17 lines
drivers/net/hyperv/rndis_filter.c +7
-0struct netvsc_device *nvscdev;u16 chn_index = new_sc->offermsg.offer.sub_channel_index;int ret; +unsigned long flags; nvscdev =hv_get_drvdata (new_sc->primary_channel->device_obj); +spin_lock_irqsave (&nvscdev->sc_lock, flags); + nvscdev->num_sc_offered--; +spin_unlock_irqrestore (&nvscdev->sc_lock, flags); +if (nvscdev->num_sc_offered ==0 ) +complete (&nvscdev->channel_init_wait); +if (chn_index >= nvscdev->num_chn)return ;@@ -1015,8 +1022,10 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 11 lines
drivers/net/hyperv/rndis_filter.c +2
-0u32 rsscap_size =sizeof (struct ndis_recv_scale_cap );u32 mtu, size;u32 num_rss_qs; +u32 sc_delta;const struct cpumask *node_cpu_mask;u32 num_possible_rss_qs; +unsigned long flags; rndis_device =get_rndis_device ();if (!rndis_device)@@ -1039,6 +1048,8 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c +2
-0net_device->max_chn =1 ; net_device->num_chn =1 ; +spin_lock_init (&net_device->sc_lock); + net_device->extension = rndis_device; rndis_device->net_dev = net_device;@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +3
-0num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); + num_rss_qs = net_device->num_chn -1 ; + net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct hv_device*dev,
Quoted 4 lines
drivers/net/hyperv/rndis_filter.c +0
-0ret =rndis_filter_set_rss_param (rndis_device, net_device- num_chn);drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1183
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +10
-0+/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); + sc_delta = net_device->num_chn -1 - num_rss_qs; + net_device->num_sc_offered -= sc_delta; +spin_unlock_irqrestore (&net_device->sc_lock, flags); + +if (net_device->num_sc_offered !=0 ) +wait_for_completion (&net_device->channel_init_wait);I'd suggest we add an essentian timeout (big, let's say 30 sec.) here. In case something goes wrong we don't really want to hang the whole kernel for forever. Such bugs are hard to debug as if a 'kernel hangs' is reported we can't be sure which wait caused it. We can even have something like:
Quoted 6 lines
t =
wait_for_completion_timeout(&net_device->channel_init_wait, 30*HZ);BUG_ON(t == 0);This is much better as we'll be sure what went wrong. (I know other pieces of hyper-v code use
wait_for_completion()without a timeout, this is rather a general suggestion for all of them).
Quoted 6 lines
There is some history here. Initially, I had timeout for calls where we could reasonably rollback state if we timed out. Some calls were subsequently changed to unconditional wait because under some load conditions, these timeouts would trigger (granted I did not have 30 second timeout; it was a 5 second timeout).
Greg was opposed to calls to
BUG_ON()in general for drivers.
Even WARN() in my opinion should do the job: we'll at least have something in the log.
Quoted 3 lines
Consequently, I have chosen to
wait unconditionally in cases where there is no sensible rollback if we were to timeout (rather thank bug checking).
(irrelevant to this patch but) in that case I'd suggest we have something like:
while (1) {
t = wait_for_completion_timeout(&..., 10*HZ);
if (t)
break;
WARN(1, "Timeout while waiting for hypervisor to reply! Keep waiting...");
}The sole purpose of that is to have something in dmesg.
Quoted 4 lines
In this specific case though, we can have a timeout and we don't need to bug check if we timeout.
I will make this change and resubmit.
Thanks!
Quoted 17 lines
Thanks,
K. Y
Quoted 13 lines
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1192
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +1
-0out:if (ret) { net_device->max_chn =1 ; net_device->num_chn =1 ; } +return 0 ;/* return 0 because primary channel can be used alone */ err_dev_remv:--
Vitaly
Signature · 1 line
Vitaly
Quoted 166 lines
-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Friday, July 17, 2015 9:10 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Dexuan Cui
Subject: Re: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probeQuoted 42 lines · KY Srinivasan
Quoted 42 lines
-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Friday, July 17, 2015 7:13 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Dexuan Cui
Subject: Re: [PATCH net-next 1/1]hv_netvsc: Wait for sub-channels to be processed during probeQuoted 1 line · K. Y. Srinivasan
The current code returns from probe without waiting for the proper
handling
Quoted 1 line
of subchannels that may be requested. If the netvsc driver were to be
rapidly
Quoted 2 lines
loaded/unloaded, we can trigger a panic as the unload will be tearing down state that may not have been fully setup yet. We fix this issue by
making
Review
Quoted 11 lines
sure that we return from the probe call only after ensuring that the sub-channel offers in flight are properly handled.
Signed-off-by K. Y. Srinivasan <[email protected]>Reviewed-and-tested-by Haiyang Zhang <[email protected]--- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/net/hyperv/hyperv_net.hQuoted 11 lines
index 26cd14c..925b75d 100644
drivers/net/hyperv/hyperv_net.h +2
-0@@ -671,6 +671,8 @@ struct netvsc_device {u32 send_table[VRSS_SEND_TAB_SIZE ];u32 max_chn;u32 num_chn; +spinlock_t sc_lock;/* Protects num_sc_offered variable */ +u32 num_sc_offered;atomic_t queue_sends[NR_CPUS ];Quoted 7 lines
Quoted 7 lines
Review
Quoted 2 lines
drivers/net/hyperv/hyperv_net.h +0
-0/* Holds rndis device info */ (quoted diff) +0
-0
b/drivers/net/hyperv/rndis_filter.cdrivers/net/hyperv/rndis_filter.c static void netvsc_sc_open(struct
Quoted 4 lines
index 2e40417..2e09f3f 100644
drivers/net/hyperv/rndis_filter.c +0
-0@@ -984,9 +984,16 @@ static void netvsc_sc_open(struct
vmbus_channelQuoted 73 lines
Quoted 73 lines
*new_sc)drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 17 lines
drivers/net/hyperv/rndis_filter.c +7
-0struct netvsc_device *nvscdev;u16 chn_index = new_sc->offermsg.offer.sub_channel_index;int ret; +unsigned long flags; nvscdev =hv_get_drvdata (new_sc->primary_channel->device_obj); +spin_lock_irqsave (&nvscdev->sc_lock, flags); + nvscdev->num_sc_offered--; +spin_unlock_irqrestore (&nvscdev->sc_lock, flags); +if (nvscdev->num_sc_offered ==0 ) +complete (&nvscdev->channel_init_wait); +if (chn_index >= nvscdev->num_chn)return ;@@ -1015,8 +1022,10 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 11 lines
drivers/net/hyperv/rndis_filter.c +2
-0u32 rsscap_size =sizeof (struct ndis_recv_scale_cap );u32 mtu, size;u32 num_rss_qs; +u32 sc_delta;const struct cpumask *node_cpu_mask;u32 num_possible_rss_qs; +unsigned long flags; rndis_device =get_rndis_device ();if (!rndis_device)@@ -1039,6 +1048,8 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 9 lines
drivers/net/hyperv/rndis_filter.c +2
-0net_device->max_chn =1 ; net_device->num_chn =1 ; +spin_lock_init (&net_device->sc_lock); + net_device->extension = rndis_device; rndis_device->net_dev = net_device;@@ -1116,6 +1127,9 @@ int rndis_filter_device_add(struct hv_device*dev,
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +3
-0num_possible_rss_qs =cpumask_weight (node_cpu_mask); net_device->num_chn =min (num_possible_rss_qs, num_rss_qs); + num_rss_qs = net_device->num_chn -1 ; + net_device->num_sc_offered = num_rss_qs; +if (net_device->num_chn ==1 ) goto out;@@ -1157,11 +1171,22 @@ int rndis_filter_device_add(struct hv_device*dev,
Quoted 4 lines
drivers/net/hyperv/rndis_filter.c +0
-0ret =rndis_filter_set_rss_param (rndis_device, net_device- num_chn);drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1183
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +10
-0+/* +* Wait for the host to send us the sub-channel offers. +*/ +spin_lock_irqsave (&net_device->sc_lock, flags); + sc_delta = net_device->num_chn -1 - num_rss_qs; + net_device->num_sc_offered -= sc_delta; +spin_unlock_irqrestore (&net_device->sc_lock, flags); + +if (net_device->num_sc_offered !=0 ) +wait_for_completion (&net_device->channel_init_wait);I'd suggest we add an essentian timeout (big, let's say 30 sec.) here. In case something goes wrong we don't really want to hang the whole kernel for forever. Such bugs are hard to debug as if a 'kernel hangs' is reported we can't be sure which wait caused it. We can even have something like:
Quoted 1 line
Quoted 1 line
t = wait_for_completion_timeout(&net_device->channel_init_wait,
30*HZ);
Quoted 7 lines
Quoted 5 lines
BUG_ON(t == 0);This is much better as we'll be sure what went wrong. (I know other pieces of hyper-v code use
wait_for_completion()without a timeout, this is rather a general suggestion for all of them).There is some history here. Initially, I had timeout for calls where we could
reasonably
Quoted 1 line
rollback state if we timed out. Some calls were subsequently changed to
unconditional
Quoted 1 line
wait because under some load conditions, these timeouts would trigger
(granted I did not
Quoted 3 lines
have 30 second timeout; it was a 5 second timeout).
Greg was opposed to calls to
BUG_ON()in general for drivers.Even
WARN()in my opinion should do the job: we'll at least have something in the log.Quoted 2 lines
Consequently, I have chosen to
wait unconditionally in cases where there is no sensible rollback if we wereto timeout (rather
Quoted 1 line
thank bug checking).
(irrelevant to this patch but) in that case I'd suggest we have something like:
Quoted 8 lines
while (1) { t = wait_for_completion_timeout(&..., 10*HZ); if (t) break; WARN(1, "Timeout while waiting for hypervisor to reply! Keep waiting..."); }The sole purpose of that is to have something in dmesg.
Agreed; I will resubmit with these changes.
Thanks,
K. Y
Quoted 29 lines
Quoted 3 lines
In this specific case though, we can have a timeout and we don't need to
bug check if we timeout.
Quoted 2 lines
I will make this change and resubmit.
Thanks!
Quoted 17 lines
Thanks,
K. Y
Quoted 13 lines
drivers/net/hyperv/rndis_filter.c int rndis_filter_device_add(struct hv_device *dev, · line 1192
Quoted 10 lines
drivers/net/hyperv/rndis_filter.c +1
-0out:if (ret) { net_device->max_chn =1 ; net_device->num_chn =1 ; } +return 0 ;/* return 0 because primary channel can be used alone */ err_dev_remv:--
Vitaly--
Vitaly