* [PATCH net] net: phy: mscc: Fix memory leak when using one step timestamping
@ 2025-05-21 13:11 Horatiu Vultur
2025-05-21 15:34 ` Antoine Tenart
0 siblings, 1 reply; 3+ messages in thread
From: Horatiu Vultur @ 2025-05-21 13:11 UTC (permalink / raw)
To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran, kory.maincent, shannon.nelson, viro, atenart,
quentin.schulz
Cc: netdev, linux-kernel, Horatiu Vultur
Fix memory leak when running one-step timestamping. When running
one-step sync timestamping, the HW is configured to insert the TX time
into the frame, so there is no reason to keep the skb anymore. As in
this case the HW will never generate an interrupt to say that the frame
was timestamped, then the frame will never released.
Fix this by freeing the frame in case of one-step timestamping.
Fixes: 7d272e63e0979d ("net: phy: mscc: timestamping and PHC support")
Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
drivers/net/phy/mscc/mscc_ptp.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/phy/mscc/mscc_ptp.c b/drivers/net/phy/mscc/mscc_ptp.c
index ed8fb14a7f215..db8ca1dfd5322 100644
--- a/drivers/net/phy/mscc/mscc_ptp.c
+++ b/drivers/net/phy/mscc/mscc_ptp.c
@@ -1173,6 +1173,13 @@ static void vsc85xx_txtstamp(struct mii_timestamper *mii_ts,
return;
}
+ if (vsc8531->ptp->tx_type == HWTSTAMP_TX_ONESTEP_SYNC) {
+ if (ptp_msg_is_sync(skb, type)) {
+ kfree_skb(skb);
+ return;
+ }
+ }
+
skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
mutex_lock(&vsc8531->ts_lock);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: phy: mscc: Fix memory leak when using one step timestamping
2025-05-21 13:11 [PATCH net] net: phy: mscc: Fix memory leak when using one step timestamping Horatiu Vultur
@ 2025-05-21 15:34 ` Antoine Tenart
2025-05-22 11:49 ` Horatiu Vultur
0 siblings, 1 reply; 3+ messages in thread
From: Antoine Tenart @ 2025-05-21 15:34 UTC (permalink / raw)
To: Horatiu Vultur
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran, kory.maincent, shannon.nelson, viro, atenart,
netdev, linux-kernel
On Wed, May 21, 2025 at 03:11:14PM +0200, Horatiu Vultur wrote:
> Fix memory leak when running one-step timestamping. When running
> one-step sync timestamping, the HW is configured to insert the TX time
> into the frame, so there is no reason to keep the skb anymore. As in
> this case the HW will never generate an interrupt to say that the frame
> was timestamped, then the frame will never released.
> Fix this by freeing the frame in case of one-step timestamping.
>
> Fixes: 7d272e63e0979d ("net: phy: mscc: timestamping and PHC support")
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> ---
> drivers/net/phy/mscc/mscc_ptp.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/net/phy/mscc/mscc_ptp.c b/drivers/net/phy/mscc/mscc_ptp.c
> index ed8fb14a7f215..db8ca1dfd5322 100644
> --- a/drivers/net/phy/mscc/mscc_ptp.c
> +++ b/drivers/net/phy/mscc/mscc_ptp.c
> @@ -1173,6 +1173,13 @@ static void vsc85xx_txtstamp(struct mii_timestamper *mii_ts,
> return;
> }
>
> + if (vsc8531->ptp->tx_type == HWTSTAMP_TX_ONESTEP_SYNC) {
> + if (ptp_msg_is_sync(skb, type)) {
> + kfree_skb(skb);
> + return;
> + }
> + }
I don't remember everything about TS but I think the above is fine. Also
while looking at this I saw this function is doing the following too:
if (!vsc8531->ptp->configured)
return;
I guess we should free the skb for all paths not putting it in the tx
queue. As there would be 3 paths freeing the skb + returning, you might
as well use a label for easier maintenance.
Thanks,
Antoine
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: phy: mscc: Fix memory leak when using one step timestamping
2025-05-21 15:34 ` Antoine Tenart
@ 2025-05-22 11:49 ` Horatiu Vultur
0 siblings, 0 replies; 3+ messages in thread
From: Horatiu Vultur @ 2025-05-22 11:49 UTC (permalink / raw)
To: Antoine Tenart
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
richardcochran, kory.maincent, shannon.nelson, viro, netdev,
linux-kernel
The 05/21/2025 17:34, Antoine Tenart wrote:
Hi Antoine,
>
> On Wed, May 21, 2025 at 03:11:14PM +0200, Horatiu Vultur wrote:
> > Fix memory leak when running one-step timestamping. When running
> > one-step sync timestamping, the HW is configured to insert the TX time
> > into the frame, so there is no reason to keep the skb anymore. As in
> > this case the HW will never generate an interrupt to say that the frame
> > was timestamped, then the frame will never released.
> > Fix this by freeing the frame in case of one-step timestamping.
> >
> > Fixes: 7d272e63e0979d ("net: phy: mscc: timestamping and PHC support")
> > Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> > ---
> > drivers/net/phy/mscc/mscc_ptp.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/drivers/net/phy/mscc/mscc_ptp.c b/drivers/net/phy/mscc/mscc_ptp.c
> > index ed8fb14a7f215..db8ca1dfd5322 100644
> > --- a/drivers/net/phy/mscc/mscc_ptp.c
> > +++ b/drivers/net/phy/mscc/mscc_ptp.c
> > @@ -1173,6 +1173,13 @@ static void vsc85xx_txtstamp(struct mii_timestamper *mii_ts,
> > return;
> > }
> >
> > + if (vsc8531->ptp->tx_type == HWTSTAMP_TX_ONESTEP_SYNC) {
> > + if (ptp_msg_is_sync(skb, type)) {
> > + kfree_skb(skb);
> > + return;
> > + }
> > + }
>
> I don't remember everything about TS but I think the above is fine. Also
> while looking at this I saw this function is doing the following too:
>
> if (!vsc8531->ptp->configured)
> return;
>
> I guess we should free the skb for all paths not putting it in the tx
> queue. As there would be 3 paths freeing the skb + returning, you might
> as well use a label for easier maintenance.
Yes, you are correct we should free the skb also in this case.
I will fix this in the next version.
>
> Thanks,
> Antoine
--
/Horatiu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-22 11:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-21 13:11 [PATCH net] net: phy: mscc: Fix memory leak when using one step timestamping Horatiu Vultur
2025-05-21 15:34 ` Antoine Tenart
2025-05-22 11:49 ` Horatiu Vultur
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®