Netdev List
 help / color / mirror / Atom feed
From: luoxuanqiang <xuanqiang.luo@linux.dev>
To: Vadim Fedorenko <vadim.fedorenko@linux.dev>
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,
	linux-renesas-soc@vger.kernel.org, netdev@vger.kernel.org,
	niklas.soderlund@ragnatech.se, kuba@kernel.org
Subject: Re: [PATCH net v3 2/2] net: ravb: serialize PTP clock teardown
Date: Sun, 9 Aug 2026 18:29:55 +0800	[thread overview]
Message-ID: <b623478e-bb46-4691-8471-a3d5de644045@linux.dev> (raw)
In-Reply-To: <66bb2d66-63ea-4331-b835-4a559ea47fe3@linux.dev>

Hi Vadim,

在 2026/8/7 22:51, Vadim Fedorenko 写道:
> On 07/08/2026 11:14, luoxuanqiang wrote:
>> Hi Vadim,
>>
>> 在 2026/8/7 06:34, Vadim Fedorenko 写道:
>>> On 06/08/2026 10:51, xuanqiang.luo@linux.dev wrote:
>>>> 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.
>>>
>>> I think adding spinlock here is a bit of overkill. For
>>> ravb_get_ts_info() you can simply extend struct ravb_ptp to store clock
>>> index on init and reset it to -1 on ptp stop.
>>>
>> Thanks! That is a good suggestion.
>>
>> I will do this in the next version.
>>
>>> For interrupt race I think ravb_ptp_stop() can be split into disable
>>> interrupt function (like ravb_ptp_disable()) and actual clock free. In
>>> this case ravb_ptp_disable() can be run before synchronize_irq() with
>>> ptp_clock_unregister() afterwards in teardown callbacks, like it's
>>> already done for ring allocations.
>>>
>> I see the approach you described. I assume you are referring to the
>> handling in ravb_set_ringparam().
>>
>> One detail I would like to clarify is which IRQs need to be 
>> synchronized.
>> When err_mgmt_irqs is set, ravb_multi_interrupt() is registered for dia,
>> err_a and mgmt_a, while only dia is stored in ndev->irq. Each handler
>> checks ISS and may call ravb_ptp_interrupt().
>>
>> Is there a hardware routing guarantee that gPTP interrupts are only
>> delivered through dia, making synchronize_irq(ndev->irq) sufficient?
>> Otherwise, it seems that the driver needs to retain the err_a and mgmt_a
>> IRQ numbers and synchronize all three before unregistering the clock.
>
> I don't have access to the datasheet, so I cannot be sure, but from 
> the quick look at the handler, there are 3 types of interrupt-handling
> functions, and 3 different interrupt vectors...
>
> But it's still better to ask people who have access to datasheet, and
> implement things in correct way rather than throwing spinlocks in the
> code.
>
> btw, do you have a HW to reproduce the issue and check the fix?
>
>
Unfortunately, I do not have the hardware. While fixing the clear issue
in patch 1, Jakub forwarded a Sashiko report that flagged this race, which
I have only verified through static code review.

Thanks,
Xuanqiang


      reply	other threads:[~2026-08-09 10:30 UTC|newest]

Thread overview: 8+ 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 ` [PATCH net v3 2/2] net: ravb: serialize PTP clock teardown xuanqiang.luo
2026-08-06 22:34   ` Vadim Fedorenko
2026-08-07 10:14     ` luoxuanqiang
2026-08-07 14:51       ` Vadim Fedorenko
2026-08-09 10:29         ` luoxuanqiang [this message]

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=b623478e-bb46-4691-8471-a3d5de644045@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 \
    --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