net/netvsc: fix mtu_set in netvsc devices
PATCH 1/1 net/netvsc: fix mtu_set in netvsc devices
Prevent segfault in hn_reinit() caused by changing the MTU for an incompletely initialized device.
--- drivers/net/netvsc/hn_ethdev.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/netvsc/hn_ethdev.c +10 -6
@@ -1127,8 +1127,10 @@ hn_reinit(struct rte_eth_dev *dev, uint16_t mtu)int i, ret =0 ;/* Point primary queues at new primary channel */ - rxqs[0 ]->chan = hv->channels[0 ]; - txqs[0 ]->chan = hv->channels[0 ]; +if (rxqs[0 ]) { + rxqs[0 ]->chan = hv->channels[0 ]; + txqs[0 ]->chan = hv->channels[0 ]; + } ret =hn_attach (hv, mtu);if (ret)
@@ -1140,10 +1142,12 @@ hn_reinit(struct rte_eth_dev *dev, uint16_t mtu)return ret;/* Point any additional queues at new subchannels */ -for (i =1 ; i < dev->data->nb_rx_queues; i++) - rxqs[i]->chan = hv->channels[i]; -for (i =1 ; i < dev->data->nb_tx_queues; i++) - txqs[i]->chan = hv->channels[i]; +if (rxqs[0 ]) { +for (i =1 ; i < dev->data->nb_rx_queues; i++) + rxqs[i]->chan = hv->channels[i]; +for (i =1 ; i < dev->data->nb_tx_queues; i++) + txqs[i]->chan = hv->channels[i]; + }return ret; }
Signature · 1 line
2.34.1
Quoted 4 lines · On Fri, 28 Jun 2024 18:35:03 +0200 Alexander Skorichenko…
Prevent segfault in
hn_reinit()caused by changing the MTU for an incompletely initialized device.Signed-off-by Alexander Skorichenko <[email protected]>
How do you get in that state?
Maybe the init code should set up these pointers and avoid the problem.
Hello,
The failure happens when running under VPP. In terms of dpdk calls the following sequence of events occurs for a NetVSC device:
Durung device probing stage of VPP
1. eth_hn_dev_init() memory for a single primary rx_queue is allocated dev->data->rx_queues[0] = 0, allocated, but not set yet no allocation happened for tx_queues[i] and non-primary
rx_queues[i]
During device setup stage of VPP from VPP's own generic dpdk_device_setup():
2. rte_eth_dev_set_mtu()
currently it segfaults in hn_reinit() when trying to reach into dev->data->rx_queues[i], dev->data->tx_queues[i]
3. rte_eth_tx_queue_setup()
dev->data->tx_queues[i] are being allocated and set
4. rte_eth_rx_queue_setup()
dev->data->rx_queues[i] get allocated (i > 0) and setSo rx_queues[0] could be set in step 1, but rx_queues[i] and tx_queues[i] are still NULL.
Allocating all the remaining rx/tx queues in step 1 would prevent the crash, but then in steps 3-4 would go through releasing and allocating all of the queues again.
Another comment regarding the uniform condition introduced in hn_reinit() in the patch:
if (dev->data->rx_queues[0] != NULL) ...
Because of the difference between rx/tx queues described above, it's
probably safer to extend the condition to check both rx and tx separately
if (dev->data->rx_queues[0] != NULL && dev->data->tx_queues[0] !=NULL)
- Alexander Skorichenko
Quoted 11 lines · Stephen Hemminger
Quoted 4 lines · On Fri, 28 Jun 2024 18:35:03 +0200 Alexander Skorichenko…
Prevent segfault in
hn_reinit()caused by changing the MTU for an incompletely initialized device.Signed-off-by Alexander Skorichenko <[email protected]>How do you get in that state?
Maybe the init code should set up these pointers and avoid the problem.
Long Li
Acked-byThank you, Alexander.
The patch looks good to me. With this patch, do you see other problems with VPP?
I'd like to get a review from @Sam Andrew<mailto:[email protected]>.
From: Alexander Skorichenko <[email protected]>
Sent: Tuesday, July 2, 2024 1:49 AM
To: [email protected]
Cc: Sam Andrew <[email protected]>; [email protected]; [email protected]; Long Li <[email protected]>; Wei Hu <[email protected]>; [email protected]; Matthew Smith <[email protected]>
Subject: Re: [PATCH] net/netvsc: fix mtu_set in netvsc devices
You don't often get email from [email protected]<mailto:[email protected]>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification> Hello,
The failure happens when running under VPP. In terms of dpdk calls the following sequence of events occurs for a NetVSC device:
Durung device probing stage of VPP
1. eth_hn_dev_init() memory for a single primary rx_queue is allocated dev->data->rx_queues[0] = 0, allocated, but not set yet no allocation happened for tx_queues[i] and non-primary rx_queues[i]
During device setup stage of VPP from VPP's own generic dpdk_device_setup():
2. rte_eth_dev_set_mtu()
currently it segfaults in hn_reinit() when trying to reach into dev->data->rx_queues[i], dev->data->tx_queues[i]
3. rte_eth_tx_queue_setup()
dev->data->tx_queues[i] are being allocated and set
4. rte_eth_rx_queue_setup()
dev->data->rx_queues[i] get allocated (i > 0) and setSo rx_queues[0] could be set in step 1, but rx_queues[i] and tx_queues[i] are still NULL.
Allocating all the remaining rx/tx queues in step 1 would prevent the crash, but then in steps 3-4 would go through releasing and allocating all of the queues again.
Another comment regarding the uniform condition introduced in hn_reinit() in the patch:
if (dev->data->rx_queues[0] != NULL) ...
Because of the difference between rx/tx queues described above, it's probably safer to extend the condition to check both rx and tx separately
if (dev->data->rx_queues[0] != NULL && dev->data->tx_queues[0] != NULL)- Alexander Skorichenko
Thanks.
Quoted 1 line
Quoted 1 line
With this patch, do you see other problems with VPP?
No further problems were noticed and MTU can be set to custom values.
- Alexander Skorichenko
Quoted 15 lines · Long Li
Thank you, Alexander.
The patch looks good to me. With this patch, do you see other problems with VPP?
I’d like to get a review from @Sam Andrew <[email protected]>.
Acked-by Long Li <[email protected]>
Thank you so much, Alexander. I’ve reviewed the patch. It looks good to me as well.
From: Alexander Skorichenko <[email protected]>
Sent: Wednesday, July 3, 2024 3:14 AM
To: Long Li <[email protected]>
Cc: [email protected]; Sam Andrew <[email protected]>; [email protected]; [email protected]; Wei Hu <[email protected]>; [email protected]
Subject: [EXTERNAL] Re: [PATCH] net/netvsc: fix mtu_set in netvsc devices
You don't often get email from [email protected]<mailto:[email protected]>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification> Thanks.
Quoted 1 line
Quoted 1 line
With this patch, do you see other problems with VPP?
No further problems were noticed and MTU can be set to custom values.
- Alexander Skorichenko
On Wed, Jul 3, 2024 at 2:35 AM Long Li <[email protected]<mailto:[email protected]>> wrote:
Thank you, Alexander.
The patch looks good to me. With this patch, do you see other problems with VPP?
I’d like to get a review from @Sam Andrew<mailto:[email protected]>.
From: Sam Andrew <[email protected]>
Sent: Wednesday, July 3, 2024 3:50 PM
To: Alexander Skorichenko <[email protected]>; Long Li <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Wei Hu <[email protected]>; [email protected]
Subject: RE: [EXTERNAL] Re: [PATCH] net/netvsc: fix mtu_set in netvsc devices
Thank you so much, Alexander. I’ve reviewed the patch. It looks good to me as well.
From: Alexander Skorichenko <[email protected]<mailto:[email protected]>>
Sent: Wednesday, July 3, 2024 3:14 AM
To: Long Li <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>; Sam Andrew <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; Wei Hu <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>
Subject: [EXTERNAL] Re: [PATCH] net/netvsc: fix mtu_set in netvsc devices
You don't often get email from [email protected]<mailto:[email protected]>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification> Thanks.
Quoted 1 line
Quoted 1 line
With this patch, do you see other problems with VPP?
No further problems were noticed and MTU can be set to custom values.
- Alexander Skorichenko
On Wed, Jul 3, 2024 at 2:35 AM Long Li <[email protected]<mailto:[email protected]>> wrote:
Thank you, Alexander.
The patch looks good to me. With this patch, do you see other problems with VPP?
I’d like to get a review from @Sam Andrew<mailto:[email protected]>.
Quoted 5 lines · Alexander Skorichenko
Prevent segfault in
hn_reinit()caused by changing the MTU for an incompletely initialized device.Signed-off-by Alexander Skorichenko <[email protected]>
Applied to dpdk-next-net/main, thanks.