net: mana: Add Interrupt Moderation support
Subsystems (5)
PATCH v3 1/1 net: mana: Add Interrupt Moderation support
From: Haiyang Zhang <[email protected]>
Add Static and Dynamic Interrupt Moderation (DIM) support for Rx and Tx.
Update queue creation procedure with new data struct with the related settings.
Add functions to collect stat for DIM, and workers to update DIM data and settings.
Update ethtool handler to get/set the moderation settings from a user. To avoid detach/re-attach ops, ring DIM doorbell to change settings at run time.
By default, adaptive-rx/tx (DIM) are enabled.
---
v3:
Updated to avoid detach/re-attach ops as suggested by Paolo.
v2:
Updated with comments from Jedrzej.
--- drivers/net/ethernet/microsoft/Kconfig | 1 + .../net/ethernet/microsoft/mana/gdma_main.c | 29 ++++ drivers/net/ethernet/microsoft/mana/mana_en.c | 147 +++++++++++++++- .../ethernet/microsoft/mana/mana_ethtool.c | 161 +++++++++++++++++- include/net/mana/gdma.h | 24 ++- include/net/mana/mana.h | 47 +++++ 6 files changed, 399 insertions(+), 10 deletions(-)
drivers/net/ethernet/microsoft/Kconfig +1 -0
@@ -21,6 +21,7 @@ config MICROSOFT_MANA depends on X86_64 || (ARM64 && !CPU_BIG_ENDIAN) depends on PCI_HYPERV select AUXILIARY_BUS + select DIMLIB select PAGE_POOL select NET_SHAPER help
drivers/net/ethernet/microsoft/mana/gdma_main.c +29 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* Copyright (c) 2021, Microsoft Corporation. */ +#include <linux/bitfield.h> #include <linux/debugfs.h> #include <linux/module.h> #include <linux/pci.h>
@@ -464,6 +465,7 @@ static int mana_gd_disable_queue(struct gdma_queue *queue)#define DOORBELL_OFFSET_RQ 0x400#define DOORBELL_OFFSET_CQ 0x800#define DOORBELL_OFFSET_EQ 0xFF8 +#define DOORBELL_OFFSET_DIM 0x820 static void mana_gd_ring_doorbell(struct gdma_context *gc, u32 db_index, enum gdma_queue_type q_type, u32 qid,
@@ -504,6 +506,16 @@ static void mana_gd_ring_doorbell(struct gdma_context *gc, u32 db_index, addr +=DOORBELL_OFFSET_SQ ;break ; +case GDMA_DIM : + e.dim.id = qid; + e.dim.mod_usec =FIELD_GET (MANA_INTR_MODR_USEC_MAX , tail_ptr); + e.dim.mod_usec_vld = !!(tail_ptr &MANA_INTR_MODR_USEC_VLD ); + e.dim.mod_comps =FIELD_GET (MANA_INTR_MODR_COMP_MASK , tail_ptr); + e.dim.mod_comps_vld = num_req; + + addr +=DOORBELL_OFFSET_DIM ; +break ; +default :WARN_ON (1 );return ;
@@ -538,6 +550,23 @@ void mana_gd_ring_cq(struct gdma_queue *cq, u8 arm_bit) }EXPORT_SYMBOL_NS (mana_gd_ring_cq,"NET_MANA" ); +void mana_gd_ring_dim (struct gdma_queue *cq,u32 mod_usec,bool mod_usec_vld, +u32 mod_comps,bool mod_comps_vld) +{ +struct gdma_context *gc = cq->gdma_dev->gdma_context; +u32 dim_val; + +/* Convert the DIM values to doorbell parameters */ + dim_val =FIELD_PREP (MANA_INTR_MODR_USEC_MAX , mod_usec) | +FIELD_PREP (MANA_INTR_MODR_COMP_MASK , mod_comps); +if (mod_usec_vld) + dim_val |=MANA_INTR_MODR_USEC_VLD ; + +mana_gd_ring_doorbell (gc, cq->gdma_dev->doorbell,GDMA_DIM , cq->id, + dim_val, mod_comps_vld); +} +EXPORT_SYMBOL_NS (mana_gd_ring_dim,"NET_MANA" ); +#define MANA_SERVICE_PERIOD 10static void mana_serv_rescan (struct pci_dev *pdev)
drivers/net/ethernet/microsoft/mana/mana_en.c +146 -1
219 lines not on this page · raw message
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +153 -8
193 lines not on this page · raw message
include/net/mana/gdma.h +23 -1
@@ -47,6 +47,7 @@ enum gdma_queue_type {GDMA_RQ ,GDMA_CQ ,GDMA_EQ , + GDMA_DIM, }; enum gdma_work_request_flags {
@@ -126,6 +127,17 @@ union gdma_doorbell_entry { u64 tail_ptr : 31; u64 arm : 1; } eq; + +struct { +u64 id :24 ; +u64 reserved :8 ; +u64 mod_usec :10 ; +u64 reserve1 :5 ; +u64 mod_usec_vld :1 ; +u64 mod_comps :8 ; +u64 reserve2 :7 ; +u64 mod_comps_vld:1 ; + } dim; };/* HW DATA */ struct gdma_msg_hdr {
@@ -502,6 +514,9 @@ void mana_gd_ring_cq(struct gdma_queue *cq, u8 arm_bit);int mana_schedule_serv_work (struct gdma_context *gc,enum gdma_eqe_type type); +void mana_gd_ring_dim (struct gdma_queue *cq,u32 mod_usec,bool mod_usec_vld, +u32 mod_comps,bool mod_comps_vld); +struct gdma_wqe {u32 reserved :24 ;u32 last_vbytes :8 ;
@@ -650,6 +665,9 @@ enum {/* Driver supports self recovery on Hardware Channel timeouts */ #define GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECOVERY BIT(25) +/* Driver supports dynamic interrupt moderation - DIM */ +#define GDMA_DRV_CAP_FLAG_1_DYN_INTERRUPT_MODERATION BIT(28) +#define GDMA_DRV_CAP_FLAGS1 \ (GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \ GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \
@@ -665,7 +683,8 @@ enum {GDMA_DRV_CAP_FLAG_1_PROBE_RECOVERY | \GDMA_DRV_CAP_FLAG_1_HANDLE_STALL_SQ_RECOVERY | \GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECOVERY | \ - GDMA_DRV_CAP_FLAG_1_EQ_MSI_UNSHARE_MULTI_VPORT) +GDMA_DRV_CAP_FLAG_1_EQ_MSI_UNSHARE_MULTI_VPORT | \ + GDMA_DRV_CAP_FLAG_1_DYN_INTERRUPT_MODERATION) #define GDMA_DRV_CAP_FLAGS2 0
@@ -701,6 +720,9 @@ struct gdma_verify_ver_req {u8 os_ver_str4[128 ]; };/* HW DATA */ +/* HW supports dynamic interrupt moderation - DIM */ +#define GDMA_PF_CAP_FLAG_1_DYN_INTERRUPT_MODERATION BIT(15) +struct gdma_verify_ver_resp {struct gdma_resp_hdr hdr;u64 gdma_protocol_ver;
include/net/mana/mana.h +47 -0
95 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Calling `mana_update_rx_dim` and `mana_update_tx_dim` after `napi_complete_done` violates NAPI…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Calling mana_update_rx_dim and mana_update_tx_dim after napi_complete_done violates NAPI serialization, leading to data races and corruption of the net_dim state.
- [High] Unconditional use of the GDMA_MESSAGE_V3 format and req_cq_moderation flag breaks WQ object creation on older MANA firmwares.
- [High] NAPI is enabled before the DIM work struct is initialized, allowing NAPI to run on an uninitialized work struct.
- [High] Lockless access to the DIM enable flags lacks memory barriers, potentially exposing uninitialized DIM structures to NAPI.
- [High] TX DIM incorrectly uses enqueued packets instead of completed packets, and reads concurrent stats unsafely.
--
commit 275fa81625ff24a83b95ff846fea9070fb3193d8
Author: Haiyang Zhang <[email protected]> Date: Thu Jun 11 19:02:22 2026 +0000
net: mana: Add Interrupt Moderation support
This commit adds Static and Dynamic Interrupt Moderation (DIM) support for Rx and Tx. It updates the queue creation procedure, adds functions to collect stats for DIM, and provides ethtool handler support to get/set the moderation settings.
Quoted 15 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0@@ -1579,6 +1579,9 @@ int mana_create_wq_obj(struct mana_port_context *apc,mana_gd_init_req_hdr (&req.hdr,MANA_CREATE_WQ_OBJ ,sizeof (req),sizeof (resp)); + + req.hdr.req.msg_version =GDMA_MESSAGE_V3 ; + req.hdr.resp.msg_version =GDMA_MESSAGE_V2 ; req.vport = vport; req.wq_type = wq_type; req.wq_gdma_region = wq_spec->gdma_region;
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_create_wq_obj(struct mana_port_context *apc, · line 1595
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0@@ -1587,6 +1590,9 @@ int mana_create_wq_obj(struct mana_port_context *apc, req.cq_size = cq_spec->queue_size; req.cq_moderation_ctx_id = cq_spec->modr_ctx_id; req.cq_parent_qid = cq_spec->attached_eq; + req.req_cq_moderation = cq_spec->req_cq_moderation; + req.cq_moderation_comp = cq_spec->cq_moderation_comp; + req.cq_moderation_usec = cq_spec->cq_moderation_usec;
[Severity: High]
Does this break queue creation on older Azure host firmwares?
The code unconditionally bumps the WQ object creation request to use GDMA_MESSAGE_V3 and passes the req_cq_moderation flag. If the firmware does not support GDMA_PF_CAP_FLAG_1_DYN_INTERRUPT_MODERATION, could the firmware reject the queue creation request and break device initialization entirely?
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_poll_rx_cq(struct mana_cq *cq) · line 2417
Quoted 13 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +13
-0+static void mana_update_tx_dim (struct mana_cq *cq) +{ +struct mana_port_context *apc =netdev_priv (cq->txq->ndev); +struct dim_sample dim_sample = {}; +struct mana_txq *txq = cq->txq; + +if (!apc->tx_dim_enabled) +return ; + +dim_update_sample (READ_ONCE (cq->dim_event_ctr), txq->stats.packets, + txq->stats.bytes, &dim_sample); +net_dim (&cq->dim, &dim_sample); +}
[Severity: High]
Does this measure the CPU enqueue rate rather than the hardware completion rate?
It appears that txq->stats.packets is incremented in mana_start_xmit() upon enqueue, not during completion in mana_poll_tx_cq(). Dynamic interrupt moderation relies on measuring the actual hardware completion rate to function correctly.
Additionally, is it safe to read txq->stats.packets here without the u64_stats_fetch_begin() retry loop? Reading a 64-bit statistic locklessly without the synchronization primitives could result in torn reads on 32-bit systems.
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_cq_handler(void *context, struct gdma_queue *gdma_queue) · line 2443
Quoted 12 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7
-1@@ -2324,7 +2434,13 @@ static int mana_cq_handler(void *context, struct gdma_queue *gdma_queue)if (w < cq->budget) {mana_gd_ring_cq (gdma_queue,SET_ARM_BIT ); cq->work_done_since_doorbell =0 ; -napi_complete_done (&cq->napi, w); + +if (napi_complete_done (&cq->napi, w)) { +if (cq->type ==MANA_CQ_TYPE_RX ) +mana_update_rx_dim (cq); +else +mana_update_tx_dim (cq); + }
[Severity: High]
Is it safe to call mana_update_rx_dim() and mana_update_tx_dim() after napi_complete_done()?
Since napi_complete_done() ends the NAPI polling cycle and relinquishes mutual exclusion, and the hardware interrupt was already re-armed by mana_gd_ring_cq() right before this, couldn't a new packet trigger an interrupt immediately? This could allow NAPI to be scheduled on another CPU concurrently while this CPU is still running the DIM update, potentially corrupting the non-thread-safe net_dim() state machine.
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_create_txq(struct mana_port_context *apc, · line 2689
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-0@@ -2562,6 +2685,9 @@ static int mana_create_txq(struct mana_port_context *apc,napi_enable_locked (&cq->napi); txq->napi_initialized = true; +INIT_WORK (&cq->dim.work, mana_tx_dim_work); + cq->dim.mode =DIM_CQ_PERIOD_MODE_START_FROM_EQE ;
[Severity: High]
Could this allow NAPI to schedule an uninitialized work_struct?
napi_enable_locked() is called right before INIT_WORK(). Once NAPI is enabled, it can be scheduled to run immediately (for example, via netpoll). If NAPI executes before INIT_WORK completes, mana_update_tx_dim() would pass the uninitialized cq->dim to net_dim(), which could cause a kernel panic when it attempts to call schedule_work().
This pattern also occurs in mana_create_rxq().
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +0
-0
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_coalesce(struct net_device *ndev, · line 477
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +4
-0@@ -440,18 +474,123 @@ static int mana_set_coalesce(struct net_device *ndev, +if (enable_rx_dim) + apc->rx_dim_enabled = true; +if (enable_tx_dim) + apc->tx_dim_enabled = true;
[Severity: High]
Could the lack of memory barriers here expose uninitialized DIM structures to NAPI?
The driver initializes DIM via mana_dim_change() and then sets apc->rx_dim_enabled to true. Without an smp_store_release() here and a corresponding smp_load_acquire() in mana_update_rx_dim(), weakly-ordered CPUs like ARM64 might reorder the stores. Concurrently, NAPI polling might observe the flag as true before the initialization is fully visible in memory, potentially invoking net_dim() on garbage memory.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Simon Horman
reviewerThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
Date: Thu Jun 11 19:02:22 2026 +0000
net: mana: Add Interrupt Moderation support
This commit adds Static and Dynamic Interrupt Moderation (DIM) support for Rx and Tx. It updates the queue creation procedure, adds functions to collect stats for DIM, and provides ethtool handler support to get/set the moderation settings.
Quoted 15 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0@@ -1579,6 +1579,9 @@ int mana_create_wq_obj(struct mana_port_context *apc,mana_gd_init_req_hdr (&req.hdr,MANA_CREATE_WQ_OBJ ,sizeof (req),sizeof (resp)); + + req.hdr.req.msg_version =GDMA_MESSAGE_V3 ; + req.hdr.resp.msg_version =GDMA_MESSAGE_V2 ; req.vport = vport; req.wq_type = wq_type; req.wq_gdma_region = wq_spec->gdma_region;
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_create_wq_obj(struct mana_port_context *apc, · line 1595
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0@@ -1587,6 +1590,9 @@ int mana_create_wq_obj(struct mana_port_context *apc, req.cq_size = cq_spec->queue_size; req.cq_moderation_ctx_id = cq_spec->modr_ctx_id; req.cq_parent_qid = cq_spec->attached_eq; + req.req_cq_moderation = cq_spec->req_cq_moderation; + req.cq_moderation_comp = cq_spec->cq_moderation_comp; + req.cq_moderation_usec = cq_spec->cq_moderation_usec;
[Severity: High]
Does this break queue creation on older Azure host firmwares?
The code unconditionally bumps the WQ object creation request to use GDMA_MESSAGE_V3 and passes the req_cq_moderation flag. If the firmware does not support GDMA_PF_CAP_FLAG_1_DYN_INTERRUPT_MODERATION, could the firmware reject the queue creation request and break device initialization entirely?
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_poll_rx_cq(struct mana_cq *cq) · line 2417
Quoted 13 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +13
-0+static void mana_update_tx_dim (struct mana_cq *cq) +{ +struct mana_port_context *apc =netdev_priv (cq->txq->ndev); +struct dim_sample dim_sample = {}; +struct mana_txq *txq = cq->txq; + +if (!apc->tx_dim_enabled) +return ; + +dim_update_sample (READ_ONCE (cq->dim_event_ctr), txq->stats.packets, + txq->stats.bytes, &dim_sample); +net_dim (&cq->dim, &dim_sample); +}
[Severity: High]
Does this measure the CPU enqueue rate rather than the hardware completion rate?
It appears that txq->stats.packets is incremented in mana_start_xmit() upon enqueue, not during completion in mana_poll_tx_cq(). Dynamic interrupt moderation relies on measuring the actual hardware completion rate to function correctly.
Additionally, is it safe to read txq->stats.packets here without the u64_stats_fetch_begin() retry loop? Reading a 64-bit statistic locklessly without the synchronization primitives could result in torn reads on 32-bit systems.
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_cq_handler(void *context, struct gdma_queue *gdma_queue) · line 2443
Quoted 12 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7
-1@@ -2324,7 +2434,13 @@ static int mana_cq_handler(void *context, struct gdma_queue *gdma_queue)if (w < cq->budget) {mana_gd_ring_cq (gdma_queue,SET_ARM_BIT ); cq->work_done_since_doorbell =0 ; -napi_complete_done (&cq->napi, w); + +if (napi_complete_done (&cq->napi, w)) { +if (cq->type ==MANA_CQ_TYPE_RX ) +mana_update_rx_dim (cq); +else +mana_update_tx_dim (cq); + }
[Severity: High]
Is it safe to call mana_update_rx_dim() and mana_update_tx_dim() after napi_complete_done()?
Since napi_complete_done() ends the NAPI polling cycle and relinquishes mutual exclusion, and the hardware interrupt was already re-armed by mana_gd_ring_cq() right before this, couldn't a new packet trigger an interrupt immediately? This could allow NAPI to be scheduled on another CPU concurrently while this CPU is still running the DIM update, potentially corrupting the non-thread-safe net_dim() state machine.
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_create_txq(struct mana_port_context *apc, · line 2689
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-0@@ -2562,6 +2685,9 @@ static int mana_create_txq(struct mana_port_context *apc,napi_enable_locked (&cq->napi); txq->napi_initialized = true; +INIT_WORK (&cq->dim.work, mana_tx_dim_work); + cq->dim.mode =DIM_CQ_PERIOD_MODE_START_FROM_EQE ;
[Severity: High]
Could this allow NAPI to schedule an uninitialized work_struct?
napi_enable_locked() is called right before INIT_WORK(). Once NAPI is enabled, it can be scheduled to run immediately (for example, via netpoll). If NAPI executes before INIT_WORK completes, mana_update_tx_dim() would pass the uninitialized cq->dim to net_dim(), which could cause a kernel panic when it attempts to call schedule_work().
This pattern also occurs in mana_create_rxq().
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +0
-0
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_coalesce(struct net_device *ndev, · line 477
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +4
-0@@ -440,18 +474,123 @@ static int mana_set_coalesce(struct net_device *ndev, +if (enable_rx_dim) + apc->rx_dim_enabled = true; +if (enable_tx_dim) + apc->tx_dim_enabled = true;
[Severity: High]
Could the lack of memory barriers here expose uninitialized DIM structures to NAPI?
The driver initializes DIM via mana_dim_change() and then sets apc->rx_dim_enabled to true. Without an smp_store_release() here and a corresponding smp_load_acquire() in mana_update_rx_dim(), weakly-ordered CPUs like ARM64 might reorder the stores. Concurrently, NAPI polling might observe the flag as true before the initialization is fully visible in memory, potentially invoking net_dim() on garbage memory.
Haiyang Zhang
maintainerQuoted 68 lines
-----Original Message-----
From: Simon Horman <[email protected]>
Sent: Saturday, June 13, 2026 4:20 AM
To: [email protected]
Cc: Simon Horman <[email protected]>; [email protected]; [email protected]; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; Dexuan Cui <[email protected]>; Long Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Konstantin Taranov <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; Paul Rosswurm <[email protected]>
Subject: [EXTERNAL] Re: [PATCH net-next v3] net: mana: Add Interrupt Moderation supportThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at:
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsashiko.
dev%2F&data=05%7C02%7Chaiyangz%40microsoft.com%7Ccbca53cce3d24759006708dec 924a556%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C639169356403391033%7C Unknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJX aW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=D2ZPGJ5XznEkcL uH3Cxtze0FYOL3xxDIY%2Bg2DP508Q8%3D&reserved=0
---
Date: Thu Jun 11 19:02:22 2026 +0000net: mana: Add Interrupt Moderation support
This commit adds Static and Dynamic Interrupt Moderation (DIM) support
for
Rx and Tx. It updates the queue creation procedure, adds functions to collect stats for DIM, and provides ethtool handler support to get/set the moderation settings.Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/net/ethernet/microsoft/mana/mana_en.cdrivers/net/ethernet/microsoft/mana/mana_en.c int mana_create_wq_obj(struct mana_port_context
Quoted 4 lines
index
26aef21c6c2c8..d92e022d8533c100644drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0@@ -1579,6 +1579,9 @@ int mana_create_wq_obj(struct mana_port_context*apc,
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_create_wq_obj(struct mana_port_context
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0mana_gd_init_req_hdr (&req.hdr,MANA_CREATE_WQ_OBJ ,sizeof (req),sizeof (resp)); + + req.hdr.req.msg_version =GDMA_MESSAGE_V3 ; + req.hdr.resp.msg_version =GDMA_MESSAGE_V2 ; req.vport = vport; req.wq_type = wq_type; req.wq_gdma_region = wq_spec->gdma_region;@@ -1587,6 +1590,9 @@ int mana_create_wq_obj(struct mana_port_context*apc,
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_create_wq_obj(struct mana_port_context *apc, · line 1595
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0req.cq_size = cq_spec->queue_size; req.cq_moderation_ctx_id = cq_spec->modr_ctx_id; req.cq_parent_qid = cq_spec->attached_eq; + req.req_cq_moderation = cq_spec->req_cq_moderation; + req.cq_moderation_comp = cq_spec->cq_moderation_comp; + req.cq_moderation_usec = cq_spec->cq_moderation_usec;[Severity: High]
Does this break queue creation on older Azure host firmwares?
Quoted 7 lines
The code unconditionally bumps the WQ object creation request to use
GDMA_MESSAGE_V3and passes thereq_cq_moderationflag. If the firmware does
not supportGDMA_PF_CAP_FLAG_1_DYN_INTERRUPT_MODERATION, could the firmware
reject the queue creation request and break device initialization entirely?
Our firmware is forward compatible with newer message versions, so the old firmware still properly handles this message, just the new feature fields are ignored, and queue creation will be successful. And if the DIM capability bit is zero from FW, driver will keep the DIM feature to be off and unchangeable.
Quoted 27 lines
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_poll_rx_cq(struct mana_cq *cq) · line 2417
Quoted 13 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +13
-0+static void mana_update_tx_dim (struct mana_cq *cq) +{ +struct mana_port_context *apc =netdev_priv (cq->txq->ndev); +struct dim_sample dim_sample = {}; +struct mana_txq *txq = cq->txq; + +if (!apc->tx_dim_enabled) +return ; + +dim_update_sample (READ_ONCE (cq->dim_event_ctr), txq->stats.packets, + txq->stats.bytes, &dim_sample); +net_dim (&cq->dim, &dim_sample); +}[Severity: High]
Does this measure the CPU enqueue rate rather than the hardware completion rate?It appears that
txq->stats.packetsis incremented inmana_start_xmit()upon enqueue, not during completion inmana_poll_tx_cq(). Dynamic interrupt
moderation relies on measuring the actual hardware completion rate to function correctly.
Quoted 5 lines
Additionally, is it safe to read
txq->stats.packetshere without theu64_stats_fetch_begin()retry loop? Reading a 64-bit statistic locklessly without the synchronization primitives could result in torn reads on 32- bit
systems.
In the next patch version, I added counters to cq, and track the HW comp rate, And the reader is in the same NAPI thread to prevent any torn reads.
Quoted 21 lines
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_cq_handler(void *context, struct
Quoted 1 line
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0@@ -2324,7 +2434,13 @@ static int mana_cq_handler(void *context, struct
gdma_queue*gdma_queue)drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_cq_handler(void *context, struct gdma_queue *gdma_queue) · line 2443
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7
-1if (w < cq->budget) {mana_gd_ring_cq (gdma_queue,SET_ARM_BIT ); cq->work_done_since_doorbell =0 ; -napi_complete_done (&cq->napi, w); + +if (napi_complete_done (&cq->napi, w)) { +if (cq->type ==MANA_CQ_TYPE_RX ) +mana_update_rx_dim (cq); +else +mana_update_tx_dim (cq); + }[Severity: High]
Is it safe to callmana_update_rx_dim()andmana_update_tx_dim()afternapi_complete_done()?
Quoted 7 lines
Since
napi_complete_done()ends the NAPI polling cycle and relinquishes mutual exclusion, and the hardware interrupt was already re-armed bymana_gd_ring_cq()right before this, couldn't a new packet trigger an interrupt immediately? This could allow NAPI to be scheduled on another CPU
concurrently while this CPU is still running the DIM update, potentially corrupting the non-thread-safenet_dim()state machine.
Thanks, I moved the dim update before the napi_complete_done() to avoid concurrently running it.
Quoted 14 lines
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_create_txq(struct
Quoted 1 line
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0@@ -2562,6 +2685,9 @@ static int mana_create_txq(struct
mana_port_context*apc,drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_create_txq(struct mana_port_context *apc, · line 2689
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-0napi_enable_locked (&cq->napi); txq->napi_initialized = true; +INIT_WORK (&cq->dim.work, mana_tx_dim_work); + cq->dim.mode =DIM_CQ_PERIOD_MODE_START_FROM_EQE ;[Severity: High]
Could this allow NAPI to schedule an uninitializedwork_struct?
Quoted 8 lines
napi_enable_locked()is called right beforeINIT_WORK(). Once NAPI is enabled, it can be scheduled to run immediately (for example, via netpoll).
If NAPI executes beforeINIT_WORKcompletes,mana_update_tx_dim()would pass the uninitializedcq->dimtonet_dim(), which could cause a kernel panic when it attempts to callschedule_work().This pattern also occurs in
mana_create_rxq().
I have updated the init order in the new version.
Quoted 20 lines
Review
Quoted 2 lines
(quoted diff) +0
-0
b/drivers/net/ethernet/microsoft/mana/mana_ethtool.cQuoted 3 lines
index
94e658d07a27e..67a2b282ff4da100644drivers/net/ethernet/microsoft/mana/mana_ethtool.c +0
-0[ ... ]
drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_coalesce(struct net_device
Quoted 1 line
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +0
-0@@ -440,18 +474,123 @@ static int mana_set_coalesce(struct net_device*ndev,
drivers/net/ethernet/microsoft/mana/mana_ethtool.c static int mana_set_coalesce(struct net_device *ndev, · line 590
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +4
-0+if (enable_rx_dim) + apc->rx_dim_enabled = true; +if (enable_tx_dim) + apc->tx_dim_enabled = true;[Severity: High]
Could the lack of memory barriers here expose uninitialized DIM structures to NAPI?
Quoted 7 lines
The driver initializes DIM via
mana_dim_change()and then setsapc->rx_dim_enabledto true. Without ansmp_store_release()here and a correspondingsmp_load_acquire()inmana_update_rx_dim(), weakly-ordered CPUs like ARM64 might reorder the stores. Concurrently, NAPI polling might observe the flag as true before the initialization is fully visible in memory,
potentially invokingnet_dim()on garbage memory.
I added smp_store_release() & smp_load_acquire() to fix it in the next version.
And, I will submit the next version soon.
Thanks,
- Haiyang