net: mana: Enforce TX SGE limit and fix error cleanup
Subsystems (5)
v5 cover net: mana: Enforce TX SGE limit and fix error cleanup
Add pre-transmission checks to block SKBs that exceed the hardware's SGE limit. Force software segmentation for GSO traffic and linearize non-GSO packets as needed.
Update TX error handling to drop failed SKBs and unmap resources immediately.
---
Changes in v5:
* Drop skb_is_gso() check for disabling GSO in mana_features_check().
* Register .ndo_features_check conditionally to avoid unnecessary call.
Changes in v4:
* Fix warning during build reported by kernel test robot
---
Aditya Garg (2):
net: mana: Handle SKB if TX SGEs exceed hardware limit
net: mana: Drop TX skb on post_work_request failure and unmap
resources
.../net/ethernet/microsoft/mana/gdma_main.c | 6 +-- drivers/net/ethernet/microsoft/mana/mana_en.c | 48 ++++++++++++++++--- .../ethernet/microsoft/mana/mana_ethtool.c | 2 + include/net/mana/gdma.h | 8 +++- include/net/mana/mana.h | 2 + 5 files changed, 54 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0
PATCH v5 1/2 net: mana: Handle SKB if TX SGEs exceed hardware limit
The MANA hardware supports a maximum of 30 scatter-gather entries (SGEs) per TX WQE. Exceeding this limit can cause TX failures.
Add ndo_features_check() callback to validate SKB layout before transmission. For GSO SKBs that would exceed the hardware SGE limit, clear NETIF_F_GSO_MASK to enforce software segmentation in the stack. Add a fallback in mana_start_xmit() to linearize non-GSO SKBs that still exceed the SGE limit.
Also, Add ethtool counter for SKBs linearized
---
Changes in v5:
* Drop skb_is_gso() check for disabling GSO in mana_features_check().
* Register .ndo_features_check conditionally to avoid unnecessary call.
Changes in v4:
* No change.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 41 ++++++++++++++++++- .../ethernet/microsoft/mana/mana_ethtool.c | 2 + include/net/mana/gdma.h | 8 +++- include/net/mana/mana.h | 1 + 4 files changed, 49 insertions(+), 3 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +39 -2
@@ -11,6 +11,7 @@#include <linux/mm.h> #include <linux/pci.h> #include <linux/export.h> +#include <linux/skbuff.h> #include <net/checksum.h> #include <net/ip6_checksum.h>
@@ -329,6 +330,22 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) cq = &apc->tx_qp[txq_idx].tx_cq; tx_stats = &txq->stats; +BUILD_BUG_ON (MAX_TX_WQE_SGL_ENTRIES !=MANA_MAX_TX_WQE_SGL_ENTRIES ); +#if (MAX_SKB_FRAGS +2 >MANA_MAX_TX_WQE_SGL_ENTRIES ) +if (skb_shinfo (skb)->nr_frags +2 >MAX_TX_WQE_SGL_ENTRIES ) { +/* GSO skb with Hardware SGE limit exceeded is not expected here +* as they are handled in mana_features_check() callback +*/ +if (skb_linearize (skb)) { +netdev_warn_once (ndev,"Failed to linearize skb with nr_frags=%d and is_gso=%d\n" , +skb_shinfo (skb)->nr_frags, +skb_is_gso (skb)); + goto tx_drop_count; + } + apc->eth_stats.linear_pkt_tx_cnt++; + } +#endif + pkg.tx_oob.s_oob.vcq_num = cq->gdma_id; pkg.tx_oob.s_oob.vsq_frame = txq->vsq_frame;
@@ -442,8 +459,6 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) } } -WARN_ON_ONCE (pkg.wqe_req.num_sge >MAX_TX_WQE_SGL_ENTRIES ); -if (pkg.wqe_req.num_sge <=ARRAY_SIZE (pkg.sgl_array)) { pkg.wqe_req.sgl = pkg.sgl_array; }else {
@@ -518,6 +533,25 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev)return NETDEV_TX_OK ; } +#if (MAX_SKB_FRAGS +2 >MANA_MAX_TX_WQE_SGL_ENTRIES ) +static netdev_features_t mana_features_check (struct sk_buff *skb, +struct net_device *ndev, +netdev_features_t features) +{ +if (skb_shinfo (skb)->nr_frags +2 >MAX_TX_WQE_SGL_ENTRIES ) { +/* Exceeds HW SGE limit. +* GSO case: +* Disable GSO so the stack will software-segment the skb +* into smaller skbs that fit the SGE budget. +* Non-GSO case: +* The xmit path will attempt skb_linearize() as a fallback. +*/ + features &= ~NETIF_F_GSO_MASK ; + } +return features; +} +#endif +static void mana_get_stats64 (struct net_device *ndev,struct rtnl_link_stats64 *st) {
@@ -878,6 +912,9 @@ static const struct net_device_ops mana_devops = { .ndo_open = mana_open, .ndo_stop = mana_close, .ndo_select_queue = mana_select_queue, +#if (MAX_SKB_FRAGS + 2 > MANA_MAX_TX_WQE_SGL_ENTRIES) + .ndo_features_check = mana_features_check, +#endif .ndo_start_xmit = mana_start_xmit, .ndo_validate_addr = eth_validate_addr, .ndo_get_stats64 = mana_get_stats64,
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +2 -0
@@ -71,6 +71,8 @@ static const struct mana_stats_desc mana_eth_stats[] = { {"tx_cq_err", offsetof(struct mana_ethtool_stats, tx_cqe_err)}, {"tx_cqe_unknown_type", offsetof(struct mana_ethtool_stats, tx_cqe_unknown_type)}, + {"linear_pkt_tx_cnt", offsetof(struct mana_ethtool_stats, + linear_pkt_tx_cnt)}, {"rx_coalesced_err", offsetof(struct mana_ethtool_stats, rx_coalesced_err)}, {"rx_cqe_unknown_type", offsetof(struct mana_ethtool_stats,
include/net/mana/gdma.h +7 -1
@@ -489,6 +489,8 @@ struct gdma_wqe {#define MAX_TX_WQE_SIZE 512#define MAX_RX_WQE_SIZE 256 +#define MANA_MAX_TX_WQE_SGL_ENTRIES 30 +#define MAX_TX_WQE_SGL_ENTRIES ((GDMA_MAX_SQE_SIZE - \ sizeof(struct gdma_sge) - INLINE_OOB_SMALL_SIZE) / \ sizeof(struct gdma_sge))
@@ -592,6 +594,9 @@ enum {#define GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE BIT(17)#define GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE BIT(6) +/* Driver supports linearizing the skb when num_sge exceeds hardware limit */ +#define GDMA_DRV_CAP_FLAG_1_SKB_LINEARIZE BIT(20) +#define GDMA_DRV_CAP_FLAGS1 \ (GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \ GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \
@@ -601,7 +606,8 @@ enum {GDMA_DRV_CAP_FLAG_1_DYNAMIC_IRQ_ALLOC_SUPPORT | \GDMA_DRV_CAP_FLAG_1_SELF_RESET_ON_EQE | \GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE | \ - GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE) +GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE | \ + GDMA_DRV_CAP_FLAG_1_SKB_LINEARIZE) #define GDMA_DRV_CAP_FLAGS2 0
include/net/mana/mana.h +1 -0
@@ -404,6 +404,7 @@ struct mana_ethtool_stats {u64 hc_tx_err_gdma;u64 tx_cqe_err;u64 tx_cqe_unknown_type; +u64 linear_pkt_tx_cnt;u64 rx_coalesced_err;u64 rx_cqe_unknown_type; };
Signature · 1 line
2.43.0
Re: [PATCH net-next v5 1/2] net: mana: Handle SKB if TX SGEs exceed hardware limit
Quoted 9 lines · Aditya Garg
The MANA hardware supports a maximum of 30 scatter-gather entries (SGEs) per TX WQE. Exceeding this limit can cause TX failures.
Addndo_features_check()callback to validate SKB layout before transmission. For GSO SKBs that would exceed the hardware SGE limit, clearNETIF_F_GSO_MASKto enforce software segmentation in the stack. Add a fallback inmana_start_xmit()to linearize non-GSO SKBs that still exceed the SGE limit.
Quoted 5 lines
Also, Add ethtool counter for SKBs linearized
Co-developed-by Dipayaan Roy <[email protected]>Signed-off-by Dipayaan Roy <[email protected]>Signed-off-by Aditya Garg <[email protected]>
RE: [PATCH net-next v5 1/2] net: mana: Handle SKB if TX SGEs exceed hardware limit
In reply to Aditya GargQuoted 29 lines
-----Original Message-----
From: Aditya Garg <[email protected]>
Sent: Friday, November 14, 2025 4:17 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; Dexuan Cui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Long Li <[email protected]>; Konstantin Taranov <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shiraz Saleem <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Aditya Garg <[email protected]>
Cc: Aditya Garg <[email protected]>
Subject: [PATCH net-next v5 1/2] net: mana: Handle SKB if TX SGEs exceed hardware limitThe MANA hardware supports a maximum of 30 scatter-gather entries (SGEs) per TX WQE. Exceeding this limit can cause TX failures.
Addndo_features_check()callback to validate SKB layout before transmission. For GSO SKBs that would exceed the hardware SGE limit, clearNETIF_F_GSO_MASKto enforce software segmentation in the stack. Add a fallback inmana_start_xmit()to linearize non-GSO SKBs that still exceed the SGE limit.
Quoted 5 lines
Also, Add ethtool counter for SKBs linearized
Co-developed-by Dipayaan Roy <[email protected]>Signed-off-by Dipayaan Roy <[email protected]>Signed-off-by Aditya Garg <[email protected]>
Jakub Kicinski
maintainerRe: [PATCH net-next v5 1/2] net: mana: Handle SKB if TX SGEs exceed hardware limit
In reply to Aditya Gargdrivers/net/ethernet/microsoft/mana/mana_en.c netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) · line 335
Quoted 11 lines · On Fri, 14 Nov 2025 13:16:42 -0800 Aditya Garg wrote:
The MANA hardware supports a maximum of 30 scatter-gather entries (SGEs) per TX WQE. Exceeding this limit can cause TX failures.
Addndo_features_check()callback to validate SKB layout before transmission. For GSO SKBs that would exceed the hardware SGE limit, clearNETIF_F_GSO_MASKto enforce software segmentation in the stack. Add a fallback inmana_start_xmit()to linearize non-GSO SKBs that still exceed the SGE limit.drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0+BUILD_BUG_ON (MAX_TX_WQE_SGL_ENTRIES !=MANA_MAX_TX_WQE_SGL_ENTRIES ); +#if (MAX_SKB_FRAGS +2 >MANA_MAX_TX_WQE_SGL_ENTRIES ) +if (skb_shinfo (skb)->nr_frags +2 >MAX_TX_WQE_SGL_ENTRIES ) {
nit: please try to avoid the use of ifdef if you can. This helps to avoid build breakage sneaking in as this code will be compiled out on default config on all platforms.
Instead you should be able to simply add the static condition to the if statement:
if (MAX_SKB_FRAGS + 2 > MANA_MAX_TX_WQE_SGL_ENTRIES &&
skb_shinfo(skb)->nr_frags + 2 > MAX_TX_WQE_SGL_ENTRIES) {and let the compiler (rather than preprocessor) eliminate this if () block.
Quoted 12 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +12
-0+/* GSO skb with Hardware SGE limit exceeded is not expected here +* as they are handled in mana_features_check() callback +*/ +if (skb_linearize (skb)) { +netdev_warn_once (ndev,"Failed to linearize skb with nr_frags=%d and is_gso=%d\n" , +skb_shinfo (skb)->nr_frags, +skb_is_gso (skb)); + goto tx_drop_count; + } + apc->eth_stats.linear_pkt_tx_cnt++; + } +#endif
Signature · 1 line
pw-bot: cr
Re: [PATCH net-next v5 1/2] net: mana: Handle SKB if TX SGEs exceed hardware limit
Quoted 17 lines · Jakub Kicinski
drivers/net/ethernet/microsoft/mana/mana_en.c netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) · line 335
Quoted 11 lines · On Fri, 14 Nov 2025 13:16:42 -0800 Aditya Garg wrote:
The MANA hardware supports a maximum of 30 scatter-gather entries (SGEs) per TX WQE. Exceeding this limit can cause TX failures.
Addndo_features_check()callback to validate SKB layout before transmission. For GSO SKBs that would exceed the hardware SGE limit, clearNETIF_F_GSO_MASKto enforce software segmentation in the stack. Add a fallback inmana_start_xmit()to linearize non-GSO SKBs that still exceed the SGE limit.drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0+BUILD_BUG_ON (MAX_TX_WQE_SGL_ENTRIES !=MANA_MAX_TX_WQE_SGL_ENTRIES ); +#if (MAX_SKB_FRAGS +2 >MANA_MAX_TX_WQE_SGL_ENTRIES ) +if (skb_shinfo (skb)->nr_frags +2 >MAX_TX_WQE_SGL_ENTRIES ) {nit: please try to avoid the use of ifdef if you can. This helps to avoid build breakage sneaking in as this code will be compiled out on default config on all platforms.
Quoted 9 lines
Instead you should be able to simply add the static condition to the if statement:
if (MAX_SKB_FRAGS + 2 > MANA_MAX_TX_WQE_SGL_ENTRIES && skb_shinfo(skb)->nr_frags + 2 > MAX_TX_WQE_SGL_ENTRIES) {and let the compiler (rather than preprocessor) eliminate this if () block.
Thanks for review and explanation Jakub, I will incorporate this change in next revision.
Regards,
Aditya
PATCH v5 2/2 net: mana: Drop TX skb on post_work_request failure and unmap resources
In reply to Aditya GargDrop TX packets when posting the work request fails and ensure DMA mappings are always cleaned up.
---
Changes in v5:
* No change.
Changes in v4:
* Fix warning during build reported by kernel test robot
--- drivers/net/ethernet/microsoft/mana/gdma_main.c | 6 +----- drivers/net/ethernet/microsoft/mana/mana_en.c | 7 +++---- include/net/mana/mana.h | 1 + 3 files changed, 5 insertions(+), 9 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_main.c +1 -5
@@ -1300,7 +1300,6 @@ int mana_gd_post_work_request(struct gdma_queue *wq, struct gdma_posted_wqe_info *wqe_info) {u32 client_oob_size = wqe_req->inline_oob_size; -struct gdma_context *gc;u32 sgl_data_size;u32 max_wqe_size;u32 wqe_size;
@@ -1330,11 +1329,8 @@ int mana_gd_post_work_request(struct gdma_queue *wq,if (wqe_size > max_wqe_size)return -EINVAL ; -if (wq->monitor_avl_buf && wqe_size >mana_gd_wq_avail_space (wq)) { - gc = wq->gdma_dev->gdma_context; -dev_err (gc->dev,"unsuccessful flow control!\n" ); +if (wq->monitor_avl_buf && wqe_size >mana_gd_wq_avail_space (wq))return -ENOSPC ; - }if (wqe_info) wqe_info->wqe_size_in_bu = wqe_size /GDMA_WQE_BU_SIZE ;
drivers/net/ethernet/microsoft/mana/mana_en.c +3 -4
@@ -493,9 +493,9 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev)if (err) { (void )skb_dequeue_tail (&txq->pending_skbs); +mana_unmap_skb (skb, apc);netdev_warn (ndev,"Failed to post TX OOB: %d\n" , err); - err =NETDEV_TX_BUSY ; - goto tx_busy; + goto free_sgl_ptr; } err =NETDEV_TX_OK ;
@@ -515,7 +515,6 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev) tx_stats->bytes += len + ((num_gso_seg -1 ) * gso_hs);u64_stats_update_end (&tx_stats->syncp); -tx_busy:if (netif_tx_queue_stopped (net_txq) &&mana_can_tx (gdma_sq)) {netif_tx_wake_queue (net_txq); apc->eth_stats.wake_queue++;
@@ -1683,7 +1682,7 @@ static int mana_move_wq_tail(struct gdma_queue *wq, u32 num_units)return 0 ; } -static void mana_unmap_skb (struct sk_buff *skb,struct mana_port_context *apc) +void mana_unmap_skb (struct sk_buff *skb,struct mana_port_context *apc) {struct mana_skb_head *ash = (struct mana_skb_head *)skb->head;struct gdma_context *gc = apc->ac->gdma_dev->gdma_context;
include/net/mana/mana.h +1 -0
@@ -585,6 +585,7 @@ int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed,void mana_query_phy_stats (struct mana_port_context *apc);int mana_pre_alloc_rxbufs (struct mana_port_context *apc,int mtu,int num_queues);void mana_pre_dealloc_rxbufs (struct mana_port_context *apc); +void mana_unmap_skb (struct sk_buff *skb,struct mana_port_context *apc);extern const struct ethtool_ops mana_ethtool_ops;extern struct dentry *mana_debugfs_root;
Signature · 1 line
2.43.0
RE: [PATCH net-next v5 2/2] net: mana: Drop TX skb on post_work_request failure and unmap resources
Quoted 21 lines
-----Original Message-----
From: Aditya Garg <[email protected]>
Sent: Friday, November 14, 2025 4:17 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; Dexuan Cui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Long Li <[email protected]>; Konstantin Taranov <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shiraz Saleem <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Aditya Garg <[email protected]>
Cc: Aditya Garg <[email protected]>
Subject: [PATCH net-next v5 2/2] net: mana: Drop TX skb onpost_work_requestfailure and unmap resources
Quoted 4 lines
Drop TX packets when posting the work request fails and ensure DMA mappings are always cleaned up.
Signed-off-by Aditya Garg <[email protected]>