Skip to contentSkip to conversation

gve: Secure enough bytes in the first TX desc for all TCP pkts

PATCH Applied Shailend Chand 3 participants 3 messages Apr 3, 2023 – Apr 5, 2023

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

PATCH v2 1/1 gve: Secure enough bytes in the first TX desc for all TCP pkts

Non-GSO TCP packets whose SKBs' linear portion did not include the entire TCP header were not populating the first Tx descriptor with as many bytes as the vNIC expected. This change ensures that all TCP packets populate the first descriptor with the correct number of bytes.

Fixes 893ce44df565 ("gve: Add basic driver framework for Compute Engine Virtual NIC")

---
Changes in v2:
- Clarify that the spec being mentioned is the gVNIC spec
- Add a define for the "182" magic number

 drivers/net/ethernet/google/gve/gve.h    |  2 ++
 drivers/net/ethernet/google/gve/gve_tx.c | 12 +++++-------
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/google/gve/gve.h +2 -0
index 64eb0442c82f..005cb9dfe078 100644
@@ -47,6 +47,8 @@
 
 #define GVE_RX_BUFFER_SIZE_DQO 2048
 
+#define GVE_GQ_TX_MIN_PKT_DESC_BYTES 182
+
 /* Each slot in the desc ring has a 1:1 mapping to a slot in the data ring */
 struct gve_rx_desc_queue {
 	struct gve_rx_desc *desc_ring; /* the descriptor ring */
drivers/net/ethernet/google/gve/gve_tx.c +5 -7
index 4888bf05fbed..5e11b8236754 100644
@@ -284,8 +284,8 @@ static inline int gve_skb_fifo_bytes_required(struct gve_tx_ring *tx,
 	int bytes;
 	int hlen;
 
-	hlen = skb_is_gso(skb) ? skb_checksum_start_offset(skb) +
-				 tcp_hdrlen(skb) : skb_headlen(skb);
+	hlen = skb_is_gso(skb) ? skb_checksum_start_offset(skb) + tcp_hdrlen(skb) :
+				 min_t(int, GVE_GQ_TX_MIN_PKT_DESC_BYTES, skb->len);
 
 	pad_bytes = gve_tx_fifo_pad_alloc_one_frag(&tx->tx_fifo,
 						   hlen);
@@ -454,13 +454,11 @@ static int gve_tx_add_skb_copy(struct gve_priv *priv, struct gve_tx_ring *tx, st
 	pkt_desc = &tx->desc[idx];
 
 	l4_hdr_offset = skb_checksum_start_offset(skb);
-	/* If the skb is gso, then we want the tcp header in the first segment
-	 * otherwise we want the linear portion of the skb (which will contain
-	 * the checksum because skb->csum_start and skb->csum_offset are given
-	 * relative to skb->head) in the first segment.
+	/* If the skb is gso, then we want the tcp header alone in the first segment
+	 * otherwise we want the minimum required by the gVNIC spec.
 	 */
 	hlen = is_gso ? l4_hdr_offset + tcp_hdrlen(skb) :
-			skb_headlen(skb);
+			min_t(int, GVE_GQ_TX_MIN_PKT_DESC_BYTES, skb->len);
 
 	info->skb =  skb;
 	/* We don't want to split the header, so if necessary, pad to the end
Signature · 1 line
2.40.0.348.gf938b09366-goog
#1 lore raw
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 10 lines · On Mon, 3 Apr 2023 10:28:09 -0700 you wrote:

Non-GSO TCP packets whose SKBs' linear portion did not include the entire TCP header were not populating the first Tx descriptor with as many bytes as the vNIC expected. This change ensures that all TCP packets populate the first descriptor with the correct number of bytes.

Fixes 893ce44df565 ("gve: Add basic driver framework for Compute Engine Virtual NIC")

[...]

Here is the summary with links:
- [net,v2] gve: Secure enough bytes in the first TX desc for all TCP pkts

    https://git.kernel.org/netdev/net/c/3ce934558097

You are awesome, thank you!

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

Re: [PATCH net v2] gve: Secure enough bytes in the first TX desc for all TCP pkts: manual merge

In reply to Shailend Chand

Hello,

Quoted 8 lines · Shailend Chand

Non-GSO TCP packets whose SKBs' linear portion did not include the entire TCP header were not populating the first Tx descriptor with as many bytes as the vNIC expected. This change ensures that all TCP packets populate the first descriptor with the correct number of bytes.

Fixes 893ce44df565 ("gve: Add basic driver framework for Compute Engine Virtual NIC")

FYI, we got a small conflict when merging 'net' in 'net-next' in the MPTCP tree due to this patch applied in 'net':

3ce934558097 ("gve: Secure enough bytes in the first TX desc for all
TCP pkts")

and this one from 'net-next':

75eaae158b1b ("gve: Add XDP DROP and TX support for GQI-QPL format")

----- Generic Message -----
The best is to avoid conflicts between 'net' and 'net-next' trees but if they cannot be avoided when preparing patches, a note about how to fix them is much appreciated.

The conflict has been resolved on our side[1] and the resolution we suggest is attached to this email. Please report any issues linked to this conflict resolution as it might be used by others. If you worked on the mentioned patches, don't hesitate to ACK this conflict resolution.
---------------------------

Regarding this conflict, the new "define"'s have been kept. Note that now, two "define"'s have the same value (182) but used in different contexts. Maybe someone will want to create a new patch to merge them.

Cheers,
Matt

[1] https://github.com/multipath-tcp/mptcp_net-next/commit/5ea299ff55b5

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
drivers/net/ethernet/google/gve/gve.h +0 -0
diff --cc drivers/net/ethernet/google/gve/gve.h
index e214b51d3c8b,005cb9dfe078..4b95f6e9a461
@@@ -47,10 -47,8 +47,12 @@@
  
  #define GVE_RX_BUFFER_SIZE_DQO 2048
  
+ #define GVE_GQ_TX_MIN_PKT_DESC_BYTES 182
+ 
 +#define GVE_XDP_ACTIONS 5
 +
 +#define GVE_TX_MAX_HEADER_SIZE 182
 +
  /* Each slot in the desc ring has a 1:1 mapping to a slot in the data ring */
  struct gve_rx_desc_queue {
  	struct gve_rx_desc *desc_ring; /* the descriptor ring */