From: Joe Damato <joe@dama.to>
To: Mark Bloch <mbloch@nvidia.com>
Cc: Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, Tariq Toukan <tariqt@nvidia.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
edumazet@google.com, horms@kernel.org,
linux-kernel@vger.kernel.org, daniel.machon@microchip.com,
linux-rdma@vger.kernel.org
Subject: Re: [PATCH net-next v2 4/5] net/mlx4: track whether a TX doorbell is pending
Date: Tue, 24 Nov 2026 11:45:14 -0800 [thread overview]
Message-ID: <awXpStIV4ZnZYvJC@devvm20253.cco0.facebook.com> (raw)
In-Reply-To: <fb13f8ff-41ed-4464-a182-cabbe7028ffe@nvidia.com>
On Tue, Nov 24, 2026 at 02:08:37PM +0200, Mark Bloch wrote:
>
>
> On 24/11/2026 13:55, Paolo Abeni wrote:
> > 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@dama.to>
> >>> Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
> >>> ---
> >>> 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?
>
>
> I meant the clear in mlx4_en_xmit_doorbell(). There are two paths to it:
>
> skb TX:
> mlx4_en_xmit() -> mlx4_en_tx_write_desc() -> mlx4_en_xmit_doorbell()
>
> XDP_TX:
> mlx4_en_poll_rx_cq() -> mlx4_en_process_rx_cq() -> mlx4_en_xmit_doorbell()
>
> In the XDP_TX case, mlx4_en_process_rx_cq() passes its local
> doorbell_pending by address to mlx4_en_xmit_frame(). If the TX ring is
> full, mlx4_en_xmit_frame() sets that flag and returns NETDEV_TX_BUSY
> without advancing ring->prod. At the end of the poll, the local flag
> causes mlx4_en_process_rx_cq() to call mlx4_en_xmit_doorbell()
> directly. The new clear can therefore dirty the producer cache line
> even if the poll posted no WQEs.
>
> >> 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.
>
> The proposed assignment still saves the state in ring->doorbell_pending,
> so the next mlx4_en_xmit() sees it. Returning the value from
> mlx4_en_tx_write_desc() would work too. I suggested using !send_doorbell
> because mlx4_en_xmit() already has that value and it covers BlueFlame
> as well. Patch 5 would then clear the flag after the drop path flush
Thanks for the review, Mark, and thanks Paolo for taking a look.
Mark's version seems better to me, so I'll go with that and send a v3. In
patch 5, I'll factor out the logic of clearing the flag into a helper.
Here's what patches 4 and 5 of v3 look like:
[omitting the data structure change from patch 4, which is unchanged]
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 97f27e005810..b98eb9edf4a9 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;
@@ -1099,6 +1100,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;
and patch 5:
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index b98eb9edf4a9..944146d21053 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -760,6 +760,14 @@ void mlx4_en_xmit_doorbell(struct mlx4_en_tx_ring *ring)
(__force u32)ring->doorbell_qpn, ring->doorbell_address);
}
+static void mlx4_en_flush_pending_doorbell(struct mlx4_en_tx_ring *ring)
+{
+ if (ring->doorbell_pending) {
+ mlx4_en_xmit_doorbell(ring);
+ ring->doorbell_pending = false;
+ }
+}
+
static void mlx4_en_tx_write_desc(struct mlx4_en_tx_ring *ring,
struct mlx4_en_tx_desc *tx_desc,
union mlx4_wqe_qpn_vlan qpn_vlan,
@@ -1132,6 +1140,8 @@ netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev)
tx_drop_count:
ring->tx_dropped++;
+ /* an earlier skb in this batch may have deferred the doorbell */
+ mlx4_en_flush_pending_doorbell(ring);
tx_drop:
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
---
pw-bot: cr
next prev parent reply other threads:[~2026-11-24 19:45 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 15:53 [PATCH net-next v2 0/5] net/mlx4: TX helpers and deferred doorbell fix Joe Damato
2026-11-17 15:53 ` [PATCH net-next v2 1/5] net/mlx4: factor VLAN parsing into mlx4_en_prep_vlan() Joe Damato
2026-11-17 16:16 ` sashiko-bot
2026-11-17 15:53 ` [PATCH net-next v2 2/5] net/mlx4: factor csum flags into mlx4_en_csum_flags() Joe Damato
2026-11-17 16:16 ` sashiko-bot
2026-11-17 15:53 ` [PATCH net-next v2 3/5] net/mlx4: factor HW loopback DMAC into mlx4_en_set_loopback_dmac() Joe Damato
2026-11-17 16:16 ` sashiko-bot
2026-11-17 15:53 ` [PATCH net-next v2 4/5] net/mlx4: track whether a TX doorbell is pending Joe Damato
2026-11-17 16:16 ` sashiko-bot
2026-11-24 10:46 ` Mark Bloch
2026-11-24 11:55 ` Paolo Abeni
2026-11-24 12:08 ` Mark Bloch
2026-11-24 19:45 ` Joe Damato [this message]
2026-11-17 15:53 ` [PATCH net-next v2 5/5] net/mlx4: flush pending doorbell when dropping a TX skb Joe Damato
2026-11-17 16:16 ` sashiko-bot
2026-11-17 15:57 ` [PATCH net-next v2 0/5] net/mlx4: TX helpers and deferred doorbell fix netdev-bot+sinfo
2026-11-17 16:43 ` Joe Damato
2026-11-19 22:38 ` Jakub Kicinski
2026-11-19 23:34 ` Joe Damato
2026-11-20 0:05 ` Jakub Kicinski
2026-11-20 0:31 ` Joe Damato
2026-11-24 9:30 ` Paolo Abeni
2026-11-24 10:46 ` Mark Bloch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awXpStIV4ZnZYvJC@devvm20253.cco0.facebook.com \
--to=joe@dama.to \
--cc=andrew+netdev@lunn.ch \
--cc=daniel.machon@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tariqt@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.