Skip to contentSkip to conversation

gve: add gve_features_check()

PATCH Applied Eric Dumazet 3 participants 3 messages Nov 16, 2023 – Nov 17, 2023

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

PATCH 1/1 gve: add gve_features_check()

It is suboptimal to attempt skb linearization from ndo_start_xmit() if a gso skb has pathological layout, or if host stack does not have access to the payload (TCP direct). Linearization of large skbs can also fail under memory pressure.

We should instead have an ndo_features_check() so that we can fallback to GSO, which is supported even for TCP direct, and generally much more efficient (no payload copy).

Cc Bailey Forrest <[email protected]>
Cc Willem de Bruijn <[email protected]>
Cc Jeroen de Borst <[email protected]>
Cc Praveen Kaligineedi <[email protected]>
Cc Shailend Chand <[email protected]>
Cc Ziwei Xiao <[email protected]>
---
 drivers/net/ethernet/google/gve/gve_dqo.h    |  3 ++
 drivers/net/ethernet/google/gve/gve_main.c   | 13 +++++++
 drivers/net/ethernet/google/gve/gve_tx_dqo.c | 37 ++++++++------------
 3 files changed, 31 insertions(+), 22 deletions(-)
drivers/net/ethernet/google/gve/gve_dqo.h +3 -0
index 1eb4d5fd8561f1e32813e0973f96e43221d44e6b..c36b93f0de15b569eafbcb7222492013782fd441 100644
@@ -33,6 +33,9 @@
 #define GVE_DEALLOCATE_COMPL_TIMEOUT 60
 
 netdev_tx_t gve_tx_dqo(struct sk_buff *skb, struct net_device *dev);
+netdev_features_t gve_features_check_dqo(struct sk_buff *skb,
+					 struct net_device *dev,
+					 netdev_features_t features);
 bool gve_tx_poll_dqo(struct gve_notify_block *block, bool do_clean);
 int gve_rx_poll_dqo(struct gve_notify_block *block, int budget);
 int gve_tx_alloc_rings_dqo(struct gve_priv *priv);
drivers/net/ethernet/google/gve/gve_main.c +13 -0
index 276f996f95dcc8b6ab3c5eb51958b95c19e61dd2..0b01166642b38118888fd0d2a4e73e2577876e82 100644
@@ -79,6 +79,18 @@ static int gve_verify_driver_compatibility(struct gve_priv *priv)
 	return err;
 }
 
+static netdev_features_t gve_features_check(struct sk_buff *skb,
+					    struct net_device *dev,
+					    netdev_features_t features)
+{
+	struct gve_priv *priv = netdev_priv(dev);
+
+	if (!gve_is_gqi(priv))
+		return gve_features_check_dqo(skb, dev, features);
+
+	return features;
+}
+
 static netdev_tx_t gve_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct gve_priv *priv = netdev_priv(dev);
@@ -1873,6 +1885,7 @@ static int gve_set_features(struct net_device *netdev,
 
 static const struct net_device_ops gve_netdev_ops = {
 	.ndo_start_xmit		=	gve_start_xmit,
+	.ndo_features_check	=	gve_features_check,
 	.ndo_open		=	gve_open,
 	.ndo_stop		=	gve_close,
 	.ndo_get_stats64	=	gve_get_stats,
drivers/net/ethernet/google/gve/gve_tx_dqo.c +15 -22
index 1e19b834a6130e8e32b236280ee17a21c17905fd..f59c4710f118822e30be39476f75b59595328ee0 100644
@@ -843,6 +843,16 @@ static bool gve_can_send_tso(const struct sk_buff *skb)
 	return true;
 }
 
+netdev_features_t gve_features_check_dqo(struct sk_buff *skb,
+					 struct net_device *dev,
+					 netdev_features_t features)
+{
+	if (skb_is_gso(skb) && !gve_can_send_tso(skb))
+		return features & ~NETIF_F_GSO_MASK;
+
+	return features;
+}
+
 /* Attempt to transmit specified SKB.
  *
  * Returns 0 if the SKB was transmitted or dropped.
@@ -854,11 +864,10 @@ static int gve_try_tx_skb(struct gve_priv *priv, struct gve_tx_ring *tx,
 	int num_buffer_descs;
 	int total_num_descs;
 
-	if (tx->dqo.qpl) {
-		if (skb_is_gso(skb))
-			if (unlikely(ipv6_hopopt_jumbo_remove(skb)))
-				goto drop;
+	if (skb_is_gso(skb) && unlikely(ipv6_hopopt_jumbo_remove(skb)))
+		goto drop;
 
+	if (tx->dqo.qpl) {
 		/* We do not need to verify the number of buffers used per
 		 * packet or per segment in case of TSO as with 2K size buffers
 		 * none of the TX packet rules would be violated.
@@ -868,24 +877,8 @@ static int gve_try_tx_skb(struct gve_priv *priv, struct gve_tx_ring *tx,
 		 */
 		num_buffer_descs = DIV_ROUND_UP(skb->len, GVE_TX_BUF_SIZE_DQO);
 	} else {
-		if (skb_is_gso(skb)) {
-			/* If TSO doesn't meet HW requirements, attempt to linearize the
-			 * packet.
-			 */
-			if (unlikely(!gve_can_send_tso(skb) &&
-				     skb_linearize(skb) < 0)) {
-				net_err_ratelimited("%s: Failed to transmit TSO packet\n",
-						    priv->dev->name);
-				goto drop;
-			}
-
-			if (unlikely(ipv6_hopopt_jumbo_remove(skb)))
-				goto drop;
-
-			num_buffer_descs = gve_num_buffer_descs_needed(skb);
-		} else {
-			num_buffer_descs = gve_num_buffer_descs_needed(skb);
-
+		num_buffer_descs = gve_num_buffer_descs_needed(skb);
+		if (!skb_is_gso(skb)) {
 			if (unlikely(num_buffer_descs > GVE_TX_MAX_DATA_DESCS)) {
 				if (unlikely(skb_linearize(skb) < 0))
 					goto drop;
Signature · 1 line
2.43.0.rc0.421.g78406f8d94-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Eric Dumazet

It is suboptimal to attempt skb linearization from ndo_start_xmit() if a gso skb has pathological layout, or if host stack does not have access to the payload (TCP direct). Linearization of large skbs can also fail under memory pressure.

We should instead have an ndo_features_check() so that we can fallback to GSO, which is supported even for TCP direct, and generally much more efficient (no payload copy).

Quoted 7 lines
Cc Bailey Forrest <[email protected]>
Cc Willem de Bruijn <[email protected]>
Cc Jeroen de Borst <[email protected]>
Cc Praveen Kaligineedi <[email protected]>
Cc Shailend Chand <[email protected]>
Cc Ziwei Xiao <[email protected]>
#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

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

Quoted 10 lines · On Thu, 16 Nov 2023 08:57:07 +0000 you wrote:

It is suboptimal to attempt skb linearization from ndo_start_xmit() if a gso skb has pathological layout, or if host stack does not have access to the payload (TCP direct). Linearization of large skbs can also fail under memory pressure.

We should instead have an ndo_features_check() so that we can fallback to GSO, which is supported even for TCP direct, and generally much more efficient (no payload copy).

[...]

Here is the summary with links:
- [net] gve: add gve_features_check()

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

You are awesome, thank you!

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