Skip to contentSkip to conversation

virtio-net: close() to follow mirror of open()

PATCH In review Parav Pandit 4 participants 10 messages Feb 2, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover virtio-net: close() to follow mirror of open()

Hi,

This two small patches improves ndo_close() callback to follow the mirror sequence of ndo_open() callback. This improves the code auditing and also ensure that xdp rxq info is not unregistered while NAPI on RXQ is ongoing.

Please review.

Patch summary:
patch-1 ensures that xdp rq info is unregistered after rq napi is disabled patch-2 keeps the mirror sequence for close() be mirror of open()

Parav Pandit (2):
virtio-net: Keep stop() to follow mirror sequence of open()
virtio-net: Maintain reverse cleanup order

 drivers/net/virtio_net.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#1 lore raw

PATCH 1/2 virtio-net: Keep stop() to follow mirror sequence of open()

Cited commit in fixes tag frees rxq xdp info while RQ NAPI is still enabled and packet processing may be ongoing.

Follow the mirror sequence of open() in the stop() callback. This ensures that when rxq info is unregistered, no rx packet processing is ongoing.

Fixes 754b8a21a96d ("virtio_net: setup xdp_rxq_info")
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 7e1a98430190..b7d0b54c3bb0 100644
@@ -2279,8 +2279,8 @@ static int virtnet_close(struct net_device *dev)
 	cancel_delayed_work_sync(&vi->refill);
 
 	for (i = 0; i < vi->max_queue_pairs; i++) {
-		xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq);
 		napi_disable(&vi->rq[i].napi);
+		xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq);
 		virtnet_napi_tx_disable(&vi->sq[i].napi);
 	}
 
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] virtio-net: Keep stop() to follow mirror sequence of open()

Quoted 9 lines · Thu, Feb 02, 2023 at 06:00:37AM CET, [email protected] wrote:

Cited commit in fixes tag frees rxq xdp info while RQ NAPI is still enabled and packet processing may be ongoing.

Follow the mirror sequence of open() in the stop() callback. This ensures that when rxq info is unregistered, no rx packet processing is ongoing.

Fixes 754b8a21a96d ("virtio_net: setup xdp_rxq_info")

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw

PATCH 2/2 virtio-net: Maintain reverse cleanup order

In reply to Parav Pandit

To easily audit the code, better to keep the device stop() sequence to be mirror of the device open() sequence.

---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index b7d0b54c3bb0..1f8168e0f64d 100644
@@ -2279,9 +2279,9 @@ static int virtnet_close(struct net_device *dev)
 	cancel_delayed_work_sync(&vi->refill);
 
 	for (i = 0; i < vi->max_queue_pairs; i++) {
+		virtnet_napi_tx_disable(&vi->sq[i].napi);
 		napi_disable(&vi->rq[i].napi);
 		xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq);
-		virtnet_napi_tx_disable(&vi->sq[i].napi);
 	}
 
 	return 0;
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] virtio-net: Maintain reverse cleanup order

Quoted 4 lines · Thu, Feb 02, 2023 at 06:00:38AM CET, [email protected] wrote:

To easily audit the code, better to keep the device stop() sequence to be mirror of the device open() sequence.

If this is not fixing bug (which I believe is the case), you should target it to net-next ([patch net-next] ..).

Quoted 22 lines

---
drivers/net/virtio_net.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index b7d0b54c3bb0..1f8168e0f64d 100644
@@ -2279,9 +2279,9 @@ static int virtnet_close(struct net_device *dev)
 	cancel_delayed_work_sync(&vi->refill);
 
 	for (i = 0; i < vi->max_queue_pairs; i++) {
+		virtnet_napi_tx_disable(&vi->sq[i].napi);
 		napi_disable(&vi->rq[i].napi);
 		xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq);
-		virtnet_napi_tx_disable(&vi->sq[i].napi);
 	}
 
 	return 0;
Signature · 1 line
2.26.2
#5 lore raw

RE: [PATCH 2/2] virtio-net: Maintain reverse cleanup order

Quoted 8 lines

From: Jiri Pirko <[email protected]>
Sent: Thursday, February 2, 2023 7:26 AM

Quoted 3 lines · Thu, Feb 02, 2023 at 06:00:38AM CET, [email protected] wrote:

To easily audit the code, better to keep the device stop() sequence to be mirror of the device open() sequence.

Quoted 7 lines
Quoted 1 line

If this is not fixing bug (which I believe is the case), you should target it to net- next ([patch net-next] ..).

Yes. Right. First one was fix for net-rc, second was for net-next. And 2nd depends on the first to avoid merge conflicts. So, I was unsure how to handle it.
Can you please suggest?

Quoted 19 lines
Quoted 19 lines

---
drivers/net/virtio_net.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0 -0

b7d0b54c3bb0..1f8168e0f64d 100644

drivers/net/virtio_net.c +1 -1
@@ -2279,9 +2279,9 @@ static int virtnet_close(struct net_device *dev)
 	cancel_delayed_work_sync(&vi->refill);
 
 	for (i = 0; i < vi->max_queue_pairs; i++) {
+		virtnet_napi_tx_disable(&vi->sq[i].napi);
 		napi_disable(&vi->rq[i].napi);
 		xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq);
-		virtnet_napi_tx_disable(&vi->sq[i].napi);
 	}
 
Quoted 4 lines
Quoted 4 lines
drivers/net/virtio_net.c +0 -1
 	return 0;
--

2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#6 lore raw

Re: [PATCH 2/2] virtio-net: Maintain reverse cleanup order

Quoted 10 lines · Thu, Feb 02, 2023 at 04:10:56PM CET, [email protected] wrote:
Quoted 10 lines

From: Jiri Pirko <[email protected]>
Sent: Thursday, February 2, 2023 7:26 AM

Quoted 4 lines · Thu, Feb 02, 2023 at 06:00:38AM CET, [email protected] wrote:

To easily audit the code, better to keep the device stop() sequence to be mirror of the device open() sequence.

Quoted 8 lines
Quoted 5 lines

If this is not fixing bug (which I believe is the case), you should target it to net- next ([patch net-next] ..).

Yes. Right. First one was fix for net-rc, second was for net-next. And 2nd depends on the first to avoid merge conflicts. So, I was unsure how to handle it.
Can you please suggest?

1) Send the fix to -net
2) Wait until -net is merged into -net-next
3) Send the second patch to -net-next

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

---
drivers/net/virtio_net.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0 -0

b7d0b54c3bb0..1f8168e0f64d 100644

drivers/net/virtio_net.c +1 -1
@@ -2279,9 +2279,9 @@ static int virtnet_close(struct net_device *dev)
 	cancel_delayed_work_sync(&vi->refill);
 
 	for (i = 0; i < vi->max_queue_pairs; i++) {
+		virtnet_napi_tx_disable(&vi->sq[i].napi);
 		napi_disable(&vi->rq[i].napi);
 		xdp_rxq_info_unreg(&vi->rq[i].xdp_rxq);
-		virtnet_napi_tx_disable(&vi->sq[i].napi);
 	}
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/virtio_net.c +0 -1
 	return 0;
--

2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#7 lore raw

RE: [PATCH 2/2] virtio-net: Maintain reverse cleanup order

Quoted 20 lines

From: Jiri Pirko <[email protected]>
Sent: Thursday, February 2, 2023 10:47 AM

Quoted 15 lines · Thu, Feb 02, 2023 at 04:10:56PM CET, [email protected] wrote:
Quoted 15 lines

From: Jiri Pirko <[email protected]>
Sent: Thursday, February 2, 2023 7:26 AM

Quoted 4 lines · Thu, Feb 02, 2023 at 06:00:38AM CET, [email protected] wrote:

To easily audit the code, better to keep the device stop() sequence to be mirror of the device open() sequence.

If this is not fixing bug (which I believe is the case), you should target it to net- next ([patch net-next] ..).

Quoted 8 lines
Quoted 1 line

Yes. Right. First one was fix for net-rc, second was for net-next. And 2nd

depends on the first to avoid merge conflicts.

Quoted 2 lines

So, I was unsure how to handle it.
Can you please suggest?

1) Send the fix to -net
2) Wait until -net is merged into -net-next
3) Send the second patch to -net-next

Got it. Thanks.

Dave, Jakub,
Please drop this series.
I am sending one by one to net and net-next.

maintainer Acked-by on the v1 series
#8 lore raw
In reply to Parav Pandit
Quoted 6 lines · Parav Pandit

Hi,

This two small patches improves ndo_close() callback to follow the mirror sequence of ndo_open() callback. This improves the code auditing and also ensure that xdp rxq info is not unregistered while NAPI on RXQ is ongoing.

I'm guessing -net and 1/2 for stable?

Quoted 6 lines

Please review.

Patch summary:
patch-1 ensures that xdp rq info is unregistered after rq napi is disabled patch-2 keeps the mirror sequence for close() be mirror of open()

Quoted 9 lines

Parav Pandit (2):
virtio-net: Keep stop() to follow mirror sequence of open()
virtio-net: Maintain reverse cleanup order

 drivers/net/virtio_net.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#9 lore raw
In reply to Parav Pandit
This series was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 2 Feb 2023 07:00:36 +0200 you wrote:

Hi,

This two small patches improves ndo_close() callback to follow the mirror sequence of ndo_open() callback. This improves the code auditing and also ensure that xdp rxq info is not unregistered while NAPI on RXQ is ongoing.

[...]

Here is the summary with links:
- [1/2] virtio-net: Keep stop() to follow mirror sequence of open()

    https://git.kernel.org/netdev/net/c/63b114042d8a

- [2/2] virtio-net: Maintain reverse cleanup order (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html