Re: [PATCH net-next v2 4/5] net/mlx4: track whether a TX doorbell is pending

From: Paolo Abeni

Date: Tue Nov 24 2026 - 06:55:42 EST


On 11/24/26 11:46, Mark Bloch wrote:
On 17/11/2026 17:53, Joe Damato wrote:
When the stack sets xmit_more, mlx4_en_xmit() skips the doorbell and
relies on a later call in the same batch to write it. Nothing records
that a doorbell is owed, so a path that ends the batch without writing
the doorbell leaves the WQEs posted before it unannounced to HW.

Add ring->doorbell_pending, set when the doorbell is deferred and
cleared whenever a doorbell or a BlueFlame write is issued, so such a
path can flush the deferred doorbell.

Place the flag in the cache line dirtied by mlx4_en_xmit(), next to
prod. That line has no room left, so move tx_dropped, which is only
written when an skb is dropped, to the end of the struct among the
fields not used in the fast path.

Signed-off-by: Joe Damato <joe@xxxxxxx>
Reviewed-by: Daniel Machon <daniel.machon@xxxxxxxxxxxxx>
---
v2:
- doorbell_pending moved to the area of the struct marked as cache line
used and dirtied in mlx4_en_xmit. In exchange, tx_dropped is moved
among fields not written in the fast path. It is only written for
drops and is read for stats.
- Update the commit message.

drivers/net/ethernet/mellanox/mlx4/en_tx.c | 9 +++++++--
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++-
2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 97f27e005810..123071a47bed 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -194,6 +194,7 @@ int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
ring->prod = 0;
ring->cons = 0xffffffff;
ring->last_nr_txbb = 1;
+ ring->doorbell_pending = false;
memset(ring->tx_info, 0, ring->size * sizeof(struct mlx4_en_tx_info));
memset(ring->buf, 0, ring->buf_size);
ring->free_tx_desc = mlx4_en_free_tx_desc;
@@ -757,6 +758,7 @@ void mlx4_en_xmit_doorbell(struct mlx4_en_tx_ring *ring)
iowrite32be(
#endif
(__force u32)ring->doorbell_qpn, ring->doorbell_address);
+ ring->doorbell_pending = false;

Can we keep this in mlx4_en_xmit()? XDP_TX calls this helper too, but
tracks its pending doorbell in a local variable. If the XDP TX ring
stays full for the whole poll, this store can dirty the producer cache
line even though we didn't post a single WQE.

I guess you quote the wrong slice of code and that you are referring to
mlx4_en_tx_write_desc(), right?
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index c5d564e5a581..9d8a4ea473f1 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -1074,6 +1074,7 @@ netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev)
send_doorbell = __netdev_tx_sent_queue(ring->tx_queue,
tx_info->nr_bytes,
netdev_xmit_more());
+ ring->doorbell_pending = !send_doorbell;

real_size = (real_size / 16) & 0x3f;

AFAICS, preserving the state across poll() invocation is needed
for correctness. To avoid writing the cacheline in the XDP case,
mlx4_en_tx_write_desc() could return the new ring->doorbell_pending
value.

/P