From: xuanqiang.luo@linux.dev
To: linux-renesas-soc@vger.kernel.org, netdev@vger.kernel.org,
niklas.soderlund@ragnatech.se, kuba@kernel.org
Cc: paul@pbarker.dev, andrew+netdev@lunn.ch, davem@davemloft.net,
edumazet@google.com, pabeni@redhat.com, richardcochran@gmail.com,
masaru.nagai.vx@renesas.com, sergei.shtylyov@cogentembedded.com,
luoxuanqiang@kylinos.cn, stable@vger.kernel.org
Subject: [PATCH net v3 2/2] net: ravb: serialize PTP clock teardown
Date: Thu, 6 Aug 2026 17:51:26 +0800 [thread overview]
Message-ID: <20260806095126.57803-3-xuanqiang.luo@linux.dev> (raw)
In-Reply-To: <20260806095126.57803-1-xuanqiang.luo@linux.dev>
From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
ravb_get_ts_info() can run without RTNL while ravb_ptp_stop() unregisters
the PHC. The PTP interrupt handler can race with the same teardown, so both
paths may access the clock while it is being freed.
Protect the clock pointer with priv->lock, clear it before unregistering
the PHC, and unregister the detached clock outside the lock.
Fixes: a0d2f20650e8 ("Renesas Ethernet AVB PTP clock driver")
Cc: stable@vger.kernel.org
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
---
drivers/net/ethernet/renesas/ravb_main.c | 16 ++++++++++++----
drivers/net/ethernet/renesas/ravb_ptp.c | 17 +++++++++++++----
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 3a9d9f8718216..c2220a54a2bf4 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1765,8 +1765,13 @@ static int ravb_set_ringparam(struct net_device *ndev,
static int ravb_get_ts_info(struct net_device *ndev,
struct kernel_ethtool_ts_info *info)
{
- struct ravb_private *priv = netdev_priv(ndev);
- const struct ravb_hw_info *hw_info = priv->info;
+ const struct ravb_hw_info *hw_info;
+ struct ravb_private *priv;
+ struct ptp_clock *clock;
+ unsigned long flags;
+
+ priv = netdev_priv(ndev);
+ hw_info = priv->info;
if (hw_info->gptp || hw_info->ccc_gac) {
info->so_timestamping =
@@ -1779,8 +1784,11 @@ static int ravb_get_ts_info(struct net_device *ndev,
(1 << HWTSTAMP_FILTER_NONE) |
(1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
(1 << HWTSTAMP_FILTER_ALL);
- if (priv->ptp.clock)
- info->phc_index = ptp_clock_index(priv->ptp.clock);
+ spin_lock_irqsave(&priv->lock, flags);
+ clock = priv->ptp.clock;
+ if (clock)
+ info->phc_index = ptp_clock_index(clock);
+ spin_unlock_irqrestore(&priv->lock, flags);
}
return 0;
diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
index eaf07cb8eadfa..530902a99d5ba 100644
--- a/drivers/net/ethernet/renesas/ravb_ptp.c
+++ b/drivers/net/ethernet/renesas/ravb_ptp.c
@@ -289,16 +289,17 @@ static const struct ptp_clock_info ravb_ptp_info = {
void ravb_ptp_interrupt(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
+ struct ptp_clock *clock = priv->ptp.clock;
u32 gis = ravb_read(ndev, GIS);
gis &= ravb_read(ndev, GIC);
- if (gis & GIS_PTCF) {
+ if ((gis & GIS_PTCF) && clock) {
struct ptp_clock_event event;
event.type = PTP_CLOCK_EXTTS;
event.index = 0;
event.timestamp = ravb_read(ndev, GCPT);
- ptp_clock_event(priv->ptp.clock, &event);
+ ptp_clock_event(clock, &event);
}
if (gis & GIS_PTMF) {
struct ravb_ptp_perout *perout = priv->ptp.perout;
@@ -334,16 +335,24 @@ void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev)
clock = NULL;
}
+ spin_lock_irqsave(&priv->lock, flags);
priv->ptp.clock = clock;
+ spin_unlock_irqrestore(&priv->lock, flags);
}
void ravb_ptp_stop(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
+ struct ptp_clock *clock;
+ unsigned long flags;
+ spin_lock_irqsave(&priv->lock, flags);
ravb_write(ndev, 0, GIC);
ravb_write(ndev, 0, GIS);
+ clock = priv->ptp.clock;
+ priv->ptp.clock = NULL;
+ spin_unlock_irqrestore(&priv->lock, flags);
- if (priv->ptp.clock)
- ptp_clock_unregister(priv->ptp.clock);
+ if (clock)
+ ptp_clock_unregister(clock);
}
--
2.43.0
next prev parent reply other threads:[~2026-08-06 9:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 9:51 [PATCH net v3 0/2] net: ravb: fix PTP clock lifetime xuanqiang.luo
2026-08-06 9:51 ` [PATCH net v3 1/2] net: ravb: handle unavailable PTP clock xuanqiang.luo
2026-08-06 13:37 ` Vadim Fedorenko
2026-08-06 9:51 ` xuanqiang.luo [this message]
2026-08-06 22:34 ` [PATCH net v3 2/2] net: ravb: serialize PTP clock teardown Vadim Fedorenko
2026-08-07 10:14 ` luoxuanqiang
2026-08-07 14:51 ` Vadim Fedorenko
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=20260806095126.57803-3-xuanqiang.luo@linux.dev \
--to=xuanqiang.luo@linux.dev \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=luoxuanqiang@kylinos.cn \
--cc=masaru.nagai.vx@renesas.com \
--cc=netdev@vger.kernel.org \
--cc=niklas.soderlund@ragnatech.se \
--cc=pabeni@redhat.com \
--cc=paul@pbarker.dev \
--cc=richardcochran@gmail.com \
--cc=sergei.shtylyov@cogentembedded.com \
--cc=stable@vger.kernel.org \
/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