From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: Jeongjun Park <aha310510@gmail.com>
Cc: netdev@vger.kernel.org,
Richard Cochran <richardcochran@gmail.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>,
Yangbo Lu <yangbo.lu@nxp.com>
Subject: Re: [PATCH net 1/2] ptp: fix breakage after ptp_vclock_in_use() rework
Date: Sun, 15 Jun 2025 19:03:52 +0300 [thread overview]
Message-ID: <20250615160352.qsobc7c2g3zbckp2@skbuf> (raw)
In-Reply-To: <CAO9qdTE0jt5U_dN09kPEzu-NUCds2VY1Ch2up9RoLazsc1j49w@mail.gmail.com>
On Mon, Jun 16, 2025 at 12:34:59AM +0900, Jeongjun Park wrote:
> However, I don't think it is appropriate to fix ptp_vclock_in_use().
> I agree that ptp->n_vclocks should be checked in the path where
> ptp_clock_freerun() is called, but there are many drivers that do not
> have any contact with ptp->n_vclocks in the path where
> ptp_clock_unregister() is called.
What do you mean there are many drivers that do not have any contact
with ptp->n_vclocks? It is a feature visible only to the core, and
transparent to the drivers. All drivers have contact with it, or none
do. It all depends solely upon user configuration, and not dependent at
all upon the specific driver.
> The reason I removed the ptp->n_vclocks check logic from the
> ptp_vclock_in_use() function is to prevent false positives from lockdep,
> but also to prevent the performance overhead caused by locking
> ptp->n_vclocks_mux and checking ptp->n_vclocks when calling
> ptp_vclock_in_use() from a driver that has nothing to do with
> ptp->n_vclocks.
Can you quantify the performance overhead caused by acquiring
ptp->n_vclocks_mux on unregistering physical clocks?
>
> Therefore, I think it would be appropriate to modify ptp_clock_freerun()
> like this instead of ptp_vclock_in_use():
> ---
> drivers/ptp/ptp_private.h | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
> index 528d86a33f37..abd99087f0ca 100644
> --- a/drivers/ptp/ptp_private.h
> +++ b/drivers/ptp/ptp_private.h
> @@ -104,10 +104,20 @@ static inline bool ptp_vclock_in_use(struct
> ptp_clock *ptp)
> /* Check if ptp clock shall be free running */
> static inline bool ptp_clock_freerun(struct ptp_clock *ptp)
> {
> + bool ret = false;
> +
> if (ptp->has_cycles)
> - return false;
> + return ret;
> +
> + if (mutex_lock_interruptible(&ptp->n_vclocks_mux))
> + return true;
> +
> + if (ptp_vclock_in_use(ptp) && ptp->n_vclocks)
> + ret = true;
> +
> + mutex_unlock(&ptp->n_vclocks_mux);
>
> - return ptp_vclock_in_use(ptp);
> + return ret;
> }
>
> extern const struct class ptp_class;
> --
If we leave the ptp_vclock_in_use() implementation as
"return !ptp->is_virtual_clock;", then a physical PTP clock with
n_vclocks=0 will have ptp_vclock_in_use() return true.
Do you consider that expected behavior? What does "vclocks in use"
even mean?
In any case, I do agree with the fact that we shouldn't need to acquire
a mutex in ptp_clock_unregister() to avoid racing with the sysfs device
attributes. This seems avoidable with better operation ordering
(unregister child virtual clocks when sysfs calls are no longer
possible), or the use of pre-existing "ptp->defunct", or some other
mechanism.
You can certainly expand on that idea in net-next. The lockdep splat is
a completely unrelated issue, and only that part is 'net' material.
next prev parent reply other threads:[~2025-06-15 16:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-13 17:47 [PATCH net 0/2] ptp_vclock fixes Vladimir Oltean
2025-06-13 17:47 ` [PATCH net 1/2] ptp: fix breakage after ptp_vclock_in_use() rework Vladimir Oltean
2025-06-15 15:34 ` Jeongjun Park
2025-06-15 16:03 ` Vladimir Oltean [this message]
2025-06-17 16:04 ` Jeongjun Park
2025-06-13 17:47 ` [PATCH net 2/2] ptp: allow reading of currently dialed frequency to succeed on free-running clocks Vladimir Oltean
2025-06-17 23:30 ` [PATCH net 0/2] ptp_vclock fixes patchwork-bot+netdevbpf
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=20250615160352.qsobc7c2g3zbckp2@skbuf \
--to=vladimir.oltean@nxp.com \
--cc=aha310510@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=yangbo.lu@nxp.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox