netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shailend Chand <shailend@google.com>
To: netdev@vger.kernel.org
Cc: almasrymina@google.com, davem@davemloft.net, edumazet@google.com,
	 hramamurthy@google.com, jeroendb@google.com, kuba@kernel.org,
	 pabeni@redhat.com, pkaligineedi@google.com, rushilg@google.com,
	 willemb@google.com, ziweixiao@google.com,
	 Shailend Chand <shailend@google.com>
Subject: [PATCH net-next v2 02/10] gve: Make the GQ RX free queue funcs idempotent
Date: Wed,  1 May 2024 23:25:41 +0000	[thread overview]
Message-ID: <20240501232549.1327174-3-shailend@google.com> (raw)
In-Reply-To: <20240501232549.1327174-1-shailend@google.com>

Although this is not fixing any existing double free bug, making these
functions idempotent allows for a simpler implementation of future ndo
hooks that act on a single queue.

Tested-by: Mina Almasry <almasrymina@google.com>
Reviewed-by: Praveen Kaligineedi <pkaligineedi@google.com>
Reviewed-by: Harshitha Ramamurthy <hramamurthy@google.com>
Signed-off-by: Shailend Chand <shailend@google.com>
---
 drivers/net/ethernet/google/gve/gve_rx.c | 29 ++++++++++++++++--------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/google/gve/gve_rx.c b/drivers/net/ethernet/google/gve/gve_rx.c
index 9b56e89c4f43..0a3f88170411 100644
--- a/drivers/net/ethernet/google/gve/gve_rx.c
+++ b/drivers/net/ethernet/google/gve/gve_rx.c
@@ -30,6 +30,9 @@ static void gve_rx_unfill_pages(struct gve_priv *priv,
 	u32 slots = rx->mask + 1;
 	int i;
 
+	if (!rx->data.page_info)
+		return;
+
 	if (rx->data.raw_addressing) {
 		for (i = 0; i < slots; i++)
 			gve_rx_free_buffer(&priv->pdev->dev, &rx->data.page_info[i],
@@ -69,20 +72,26 @@ static void gve_rx_free_ring_gqi(struct gve_priv *priv, struct gve_rx_ring *rx,
 	int idx = rx->q_num;
 	size_t bytes;
 
-	bytes = sizeof(struct gve_rx_desc) * cfg->ring_size;
-	dma_free_coherent(dev, bytes, rx->desc.desc_ring, rx->desc.bus);
-	rx->desc.desc_ring = NULL;
+	if (rx->desc.desc_ring) {
+		bytes = sizeof(struct gve_rx_desc) * cfg->ring_size;
+		dma_free_coherent(dev, bytes, rx->desc.desc_ring, rx->desc.bus);
+		rx->desc.desc_ring = NULL;
+	}
 
-	dma_free_coherent(dev, sizeof(*rx->q_resources),
-			  rx->q_resources, rx->q_resources_bus);
-	rx->q_resources = NULL;
+	if (rx->q_resources) {
+		dma_free_coherent(dev, sizeof(*rx->q_resources),
+				  rx->q_resources, rx->q_resources_bus);
+		rx->q_resources = NULL;
+	}
 
 	gve_rx_unfill_pages(priv, rx, cfg);
 
-	bytes = sizeof(*rx->data.data_ring) * slots;
-	dma_free_coherent(dev, bytes, rx->data.data_ring,
-			  rx->data.data_bus);
-	rx->data.data_ring = NULL;
+	if (rx->data.data_ring) {
+		bytes = sizeof(*rx->data.data_ring) * slots;
+		dma_free_coherent(dev, bytes, rx->data.data_ring,
+				  rx->data.data_bus);
+		rx->data.data_ring = NULL;
+	}
 
 	kvfree(rx->qpl_copy_pool);
 	rx->qpl_copy_pool = NULL;
-- 
2.45.0.rc0.197.gbae5840b3b-goog


  parent reply	other threads:[~2024-05-01 23:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 23:25 [PATCH net-next v2 00/10] gve: Implement queue api Shailend Chand
2024-05-01 23:25 ` [PATCH net-next v2 01/10] queue_api: define " Shailend Chand
2024-05-01 23:25 ` Shailend Chand [this message]
2024-05-01 23:25 ` [PATCH net-next v2 03/10] gve: Add adminq funcs to add/remove a single Rx queue Shailend Chand
2024-05-01 23:25 ` [PATCH net-next v2 04/10] gve: Make gve_turn(up|down) ignore stopped queues Shailend Chand
2024-05-01 23:25 ` [PATCH net-next v2 05/10] gve: Make gve_turnup work for nonempty queues Shailend Chand
2024-05-01 23:25 ` [PATCH net-next v2 06/10] gve: Avoid rescheduling napi if on wrong cpu Shailend Chand
2024-05-01 23:25 ` [PATCH net-next v2 07/10] gve: Reset Rx ring state in the ring-stop funcs Shailend Chand
2024-05-01 23:25 ` [PATCH net-next v2 08/10] gve: Account for stopped queues when reading NIC stats Shailend Chand
2024-05-01 23:25 ` [PATCH net-next v2 09/10] gve: Alloc and free QPLs with the rings Shailend Chand
2024-05-01 23:25 ` [PATCH net-next v2 10/10] gve: Implement queue api Shailend Chand
2024-05-06 18:09   ` David Wei
2024-05-06 18:47     ` Mina Almasry
2024-05-07 21:06       ` David Wei
2024-05-08 17:09         ` Mina Almasry
2024-05-09 17:46           ` David Wei
2024-05-02 15:15 ` [PATCH net-next v2 00/10] " Willem de Bruijn
2024-05-05 13:40 ` patchwork-bot+netdevbpf
2024-05-06 17:41   ` Shailend Chand
2024-05-06 18:07     ` Shailend Chand
2024-05-07  1:25       ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240501232549.1327174-3-shailend@google.com \
    --to=shailend@google.com \
    --cc=almasrymina@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hramamurthy@google.com \
    --cc=jeroendb@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pkaligineedi@google.com \
    --cc=rushilg@google.com \
    --cc=willemb@google.com \
    --cc=ziweixiao@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).