From: "Jiawen Wu" <jiawenwu@trustnetic.com>
To: "'Jacob Keller'" <jacob.e.keller@intel.com>, <netdev@vger.kernel.org>
Cc: "'Mengyuan Lou'" <mengyuanlou@net-swift.com>,
"'Andrew Lunn'" <andrew+netdev@lunn.ch>,
"'David S. Miller'" <davem@davemloft.net>,
"'Eric Dumazet'" <edumazet@google.com>,
"'Jakub Kicinski'" <kuba@kernel.org>,
"'Paolo Abeni'" <pabeni@redhat.com>,
"'Richard Cochran'" <richardcochran@gmail.com>,
"'Kees Cook'" <kees@kernel.org>,
"'Aleksandr Loktionov'" <aleksandr.loktionov@intel.com>,
"'Vadim Fedorenko'" <vadim.fedorenko@linux.dev>,
"'Sashiko'" <sashiko-bot@kernel.org>
Subject: RE: [PATCH net v2] net: libwx: fix races in Tx timestamp handling
Date: Wed, 16 Sep 2026 10:33:41 +0800 [thread overview]
Message-ID: <029101dd4583$c9a837e0$5cf8a7a0$@trustnetic.com> (raw)
In-Reply-To: <37ddac74-f30b-4143-966f-3c26cc9db323@intel.com>
On Wed, Sep 16, 2026 7:51 AM, Jacob Keller wrote:
> On 9/14/2026 1:00 AM, Jiawen Wu wrote:
> > diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> > index ed5aad7857bd..940ba2c6150f 100644
> > --- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> > +++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> > @@ -1677,19 +1682,34 @@ static netdev_tx_t wx_xmit_frame_ring(struct sk_buff *skb,
> > wx->atr(tx_ring, first, ptype);
> >
> > if (wx_tx_map(tx_ring, first, hdr_len))
> > - goto cleanup_tx_tstamp;
> > + goto out_drop;
> >
> > return NETDEV_TX_OK;
> > out_drop:
> > - dev_kfree_skb_any(first->skb);
> > - first->skb = NULL;
> > -cleanup_tx_tstamp:
> > + /* The hardware will never report a timestamp for a frame it did not
> > + * transmit, so drop the request. Only do so if it is still ours: the
> > + * PTP worker may already have completed it and a concurrent transmit
> > + * may have submitted a new one.
> > + */
>
> Could you explain this a bit more? The hardware doesn't report a
> timestamp if the frame didn't transmit.. but you say here the PTP worker
> may have already cleaned this up? How goes that work here? I guess
> clean_tx_tstamp label may execute even if the timestamp has actually
> happened and already completed? I'm not quite following this logic.
I think I was somewhat misled by the AI, the comment is wrong.
The label is not reachable for a frame what was actually transmitted.
It has only two entries, and both are before the frame is handed to the
hardware. No timestamp can be latched for such a frame, so the request
has to be cancelled. That part of the comment is accurate.
What is wrong is the reason I gave for the ownership check. The PTP
worker cannot have completed the request for a frame that was never
transmitted - it only consumes the slot when WX_TSC_1588_CTL_VALID is
set, and there is no new latch without a transmission. Bringing the
worker in there is simply incorrect.
I'll fix the comment like this:
/* The frame never reached the hardware, so no timestamp will ever be reported
* for it and the request has to be cancelled. The slot is shared, though:
* wx_ptp_clear_tx_timestamp() or wx_ptp_tx_hang() may have dropped our request
* request already, and a transmit on another queue can have claimed the slot
* since. Only cancel it while it is still ours, otherwise we would free
* somebody else's skb and release their in-progress bit.
*/
>
> > if (unlikely(tx_flags & WX_TX_FLAGS_TSTAMP)) {
> > - dev_kfree_skb_any(wx->ptp_tx_skb);
> > - wx->ptp_tx_skb = NULL;
> > - wx->tx_hwtstamp_errors++;
> > - clear_bit_unlock(WX_STATE_PTP_TX_IN_PROGRESS, wx->state);
> > + struct sk_buff *ptp_tx_skb = NULL;
> > + unsigned long flags;
> > +
> > + spin_lock_irqsave(&wx->ptp_tx_lock, flags);
> > + if (wx->ptp_tx_skb == skb) {
> > + ptp_tx_skb = wx->ptp_tx_skb;
> > + wx->ptp_tx_skb = NULL;
> > + clear_bit(WX_STATE_PTP_TX_IN_PROGRESS, wx->state);
> > + }
> > + spin_unlock_irqrestore(&wx->ptp_tx_lock, flags);
> > +
> > + if (ptp_tx_skb) {
> > + dev_kfree_skb_any(ptp_tx_skb);
> > + wx->tx_hwtstamp_errors++;
> > + }
> > }
> > + dev_kfree_skb_any(first->skb);
> > + first->skb = NULL;
> >
> > return NETDEV_TX_OK;
> > }
>
next prev parent reply other threads:[~2026-09-16 2:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 8:00 [PATCH net v2] net: libwx: fix races in Tx timestamp handling Jiawen Wu
2026-09-15 23:51 ` Jacob Keller
2026-09-16 2:33 ` Jiawen Wu [this message]
2026-09-17 20:02 ` netdev-bot+sashiko
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='029101dd4583$c9a837e0$5cf8a7a0$@trustnetic.com' \
--to=jiawenwu@trustnetic.com \
--cc=aleksandr.loktionov@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=mengyuanlou@net-swift.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=sashiko-bot@kernel.org \
--cc=vadim.fedorenko@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox