Skip to contentSkip to conversation

virtio_net: Reuse buffer free function

PATCH Applied Parav Pandit 4 participants 5 messages Jan 16, 2023 – Jan 18, 2023

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

PATCH v2 1/1 virtio_net: Reuse buffer free function

virtnet_rq_free_unused_buf() helper function to free the buffer already exists. Avoid code duplication by reusing existing function.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +1 -7
index 7723b2a49d8e..31d037df514f 100644
@@ -1251,13 +1251,7 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 	if (unlikely(len < vi->hdr_len + ETH_HLEN)) {
 		pr_debug("%s: short packet %i\n", dev->name, len);
 		dev->stats.rx_length_errors++;
-		if (vi->mergeable_rx_bufs) {
-			put_page(virt_to_head_page(buf));
-		} else if (vi->big_packets) {
-			give_pages(rq, buf);
-		} else {
-			put_page(virt_to_head_page(buf));
-		}
+		virtnet_rq_free_unused_buf(rq->vq, buf);
 		return;
 	}
 
Signature · 1 line
2.26.2
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 18 lines · Parav Pandit

virtnet_rq_free_unused_buf() helper function to free the buffer already exists. Avoid code duplication by reusing existing function.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +0 -0
index 7723b2a49d8e..31d037df514f 100644
@@ -1251,13 +1251,7 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 	if (unlikely(len < vi->hdr_len + ETH_HLEN)) {
 		pr_debug("%s: short packet %i\n", dev->name, len);
 		dev->stats.rx_length_errors++;

drivers/net/virtio_net.c static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, · line 1256

Quoted 10 lines
drivers/net/virtio_net.c +1 -7
-		if (vi->mergeable_rx_bufs) {
-			put_page(virt_to_head_page(buf));
-		} else if (vi->big_packets) {
-			give_pages(rq, buf);
-		} else {
-			put_page(virt_to_head_page(buf));
-		}
+		virtnet_rq_free_unused_buf(rq->vq, buf);
 		return;
 	}

Sure.

while we are at it how about a patch moving virtnet_rq_free_unused_buf and virtnet_sq_free_unused_buf so we don't need forward declarations?

E.g. a good place for virtnet_sq_free_unused_buf is likely after ptr_to_xdp group of functions.

For virtnet_rq_free_unused_buf - after give_pages/get_a_page.

Quoted 3 lines
Signature · 2 lines
-- 
2.26.2

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

#2 lore raw
Quoted 38 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Monday, January 16, 2023 5:13 PM

drivers/net/virtio_net.c static void receive_buf(struct virtnet_info *vi,

Quoted 15 lines · Parav Pandit

virtnet_rq_free_unused_buf() helper function to free the buffer already exists. Avoid code duplication by reusing existing function.

---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0 -0

7723b2a49d8e..31d037df514f 100644

drivers/net/virtio_net.c +0 -0
@@ -1251,13 +1251,7 @@ static void receive_buf(struct virtnet_info *vi,

struct receive_queue *rq,

drivers/net/virtio_net.c static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, · line 1256

Quoted 13 lines
drivers/net/virtio_net.c +1 -7
 	if (unlikely(len < vi->hdr_len + ETH_HLEN)) {
 		pr_debug("%s: short packet %i\n", dev->name, len);
 		dev->stats.rx_length_errors++;
-		if (vi->mergeable_rx_bufs) {
-			put_page(virt_to_head_page(buf));
-		} else if (vi->big_packets) {
-			give_pages(rq, buf);
-		} else {
-			put_page(virt_to_head_page(buf));
-		}
+		virtnet_rq_free_unused_buf(rq->vq, buf);
 		return;
 	}

Sure.

Quoted 5 lines

while we are at it how about a patch moving virtnet_rq_free_unused_buf and virtnet_sq_free_unused_buf so we don't need forward declarations?

Yes. its in my list. Will do after this patch.
I am also going to add the comment for the history about not doing ZLEN around this area.

Quoted 8 lines

E.g. a good place for virtnet_sq_free_unused_buf is likely after ptr_to_xdp group of functions.

For virtnet_rq_free_unused_buf - after give_pages/get_a_page.

Quoted 3 lines
drivers/net/virtio_net.c +0 -1
--

2.26.2

Acked-by on v2 1/1
#3 lore raw
In reply to Parav Pandit
Quoted 7 lines · Parav Pandit

virtnet_rq_free_unused_buf() helper function to free the buffer already exists. Avoid code duplication by reusing existing function.

Thanks

Quoted 24 lines
---
 drivers/net/virtio_net.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/virtio_net.c +1 -8
index 7723b2a49d8e..31d037df514f 100644
@@ -1251,13 +1251,7 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
        if (unlikely(len < vi->hdr_len + ETH_HLEN)) {
                pr_debug("%s: short packet %i\n", dev->name, len);
                dev->stats.rx_length_errors++;
-               if (vi->mergeable_rx_bufs) {
-                       put_page(virt_to_head_page(buf));
-               } else if (vi->big_packets) {
-                       give_pages(rq, buf);
-               } else {
-                       put_page(virt_to_head_page(buf));
-               }
+               virtnet_rq_free_unused_buf(rq->vq, buf);
                return;
        }
 
--
Quoted 2 lines

2.26.2

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

#4 lore raw
In reply to Parav Pandit
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 8 lines · On Mon, 16 Jan 2023 22:27:08 +0200 you wrote:

virtnet_rq_free_unused_buf() helper function to free the buffer already exists. Avoid code duplication by reusing existing function.

[...]

Here is the summary with links:
- [net-next,v2] virtio_net: Reuse buffer free function

    https://git.kernel.org/netdev/net-next/c/eb1d929f1551

You are awesome, thank you!

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