From: sashiko-bot@kernel.org
To: wei.fang@oss.nxp.com
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v3 net-next 3/8] ptp: netc: export netc_timer_get_current_time() for cross-driver use
Date: Tue, 01 Sep 2026 08:20:25 +0000 [thread overview]
Message-ID: <20260901082025.AF94B1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260831082335.1184605-4-wei.fang@oss.nxp.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Using device_lock() in an exported API to protect against driver unbind is an architectural anti-pattern that creates a circular lock dependency (lockdep warning) and limits caller contexts.
--
commit 9efea393693780854f3e912aa851d7d32115845a
Author: Wei Fang <wei.fang@nxp.com>
ptp: netc: export netc_timer_get_current_time() for cross-driver use
The NETC Switch does not have its own time registers and must obtain
the current PTP time from the NETC Timer bound to it. Since the two
are separate PCIe functions with independent drivers, add
netc_timer_get_current_time() to the Timer driver and export it via
EXPORT_SYMBOL_GPL().
> diff --git a/drivers/ptp/ptp_netc.c b/drivers/ptp/ptp_netc.c
> index aa9be8e2a6304..854a206b6c5bc 100644
> --- a/drivers/ptp/ptp_netc.c
> +++ b/drivers/ptp/ptp_netc.c
[ ... ]
> @@ -1021,5 +1021,55 @@ static struct pci_driver netc_timer_driver = {
> };
> module_pci_driver(netc_timer_driver);
>
> +/**
> + * netc_timer_get_current_time - read the current PTP time from the NETC Timer
> + * @pdev: PCI device of the NETC Timer
> + * @ns: The current PTP clock time in nanoseconds, returned to the caller
> + *
> + * Reads the 64-bit current time register (TMR_CUR_TIME) from the NETC Timer
> + * device associated with @pdev. Returns an error if the Timer driver has not
> + * yet probed or has already been removed.
> + *
> + * Context: Process context only. Acquires the device mutex via device_lock(),
> + * which may sleep. Must not be called from atomic context, softirq,
> + * BH, or while holding a spinlock.
> + *
> + * Return: 0 on success, otherwise a negative error code.
> + */
> +int netc_timer_get_current_time(struct pci_dev *pdev, u64 *ns)
> +{
> + struct device *dev = &pdev->dev;
> + struct netc_timer *priv;
> + unsigned long flags;
> + int err = 0;
> +
> + /* Serialize against driver unbind: the remove() callback runs under
> + * the device lock, so holding it here ensures that priv remains valid
> + * for the entire duration of the register read.
> + */
> + device_lock(dev);
[Severity: High]
Does acquiring the timer's device lock here create a circular lock dependency
with the switch's remove path?
When the switch driver unbinds, it acquires the switch device's dev->mutex,
then rtnl_lock() via dsa_unregister_switch(), and then onestep->work_lock
via netc_port_disable().
In the datapath workqueue, netc_onestep_work() acquires onestep->work_lock,
and calls this function, which acquires the timer's dev->mutex.
Because lockdep tracks all dev->mutex locks initialized by device_initialize()
as a single lock class, wouldn't this form a dev->mutex -> work_lock ->
dev->mutex circular dependency?
Could we prevent the timer from unbinding while the switch is active by
creating a device link with device_link_add() instead, which would allow
lock-free reads?
> +
> + if (pci_dev_driver(pdev) != &netc_timer_driver) {
> + err = -EINVAL;
> + goto unlock_device;
> + }
> +
> + priv = pci_get_drvdata(pdev);
> + if (!priv) {
> + err = -ENOMEM;
> + goto unlock_device;
> + }
> +
> + spin_lock_irqsave(&priv->lock, flags);
> + *ns = netc_timer_cur_time_read(priv);
> + spin_unlock_irqrestore(&priv->lock, flags);
> +
> +unlock_device:
> + device_unlock(dev);
> +
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(netc_timer_get_current_time);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831082335.1184605-1-wei.fang@oss.nxp.com?part=3
next prev parent reply other threads:[~2026-09-01 8:20 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 8:23 [PATCH v3 net-next 0/8] net: dsa: netc: add PTP support for NETC switch wei.fang
2026-08-31 8:23 ` [PATCH v3 net-next 1/8] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access wei.fang
2026-09-01 8:20 ` sashiko-bot
2026-09-02 1:56 ` Wei Fang (OSS)
2026-08-31 8:23 ` [PATCH v3 net-next 2/8] ptp: netc: remove unnecessary pcie_flr() call in probe wei.fang
2026-08-31 8:23 ` [PATCH v3 net-next 3/8] ptp: netc: export netc_timer_get_current_time() for cross-driver use wei.fang
2026-09-01 8:20 ` sashiko-bot [this message]
2026-09-02 2:02 ` Wei Fang (OSS)
2026-09-04 22:25 ` netdev-bot+sashiko
2026-08-31 8:23 ` [PATCH v3 net-next 4/8] net: dsa: netc: use entry ID instead of pointer to track host flood rule wei.fang
2026-09-04 22:25 ` netdev-bot+sashiko
2026-08-31 8:23 ` [PATCH v3 net-next 5/8] net: dsa: netc: check return value of ntmp_ipft_delete_entry() wei.fang
2026-09-04 22:25 ` netdev-bot+sashiko
2026-08-31 8:23 ` [PATCH v3 net-next 6/8] net: dsa: netc: enable ingress port filtering lookup by default wei.fang
2026-08-31 8:23 ` [PATCH v3 net-next 7/8] net: dsa: netc: add PTP two-step timestamping support wei.fang
2026-09-01 8:20 ` sashiko-bot
2026-09-02 2:12 ` Wei Fang (OSS)
2026-09-04 22:25 ` netdev-bot+sashiko
2026-08-31 8:23 ` [PATCH v3 net-next 8/8] net: dsa: netc: add PTP one-step " wei.fang
2026-09-01 8:20 ` sashiko-bot
2026-09-02 3:00 ` Wei Fang (OSS)
2026-09-02 3:05 ` Wei Fang (OSS)
2026-09-04 22:25 ` netdev-bot+sashiko
2026-09-05 0:52 ` Jakub Kicinski
2026-09-05 6:16 ` Linus Walleij
2026-09-01 15:09 ` [PATCH v3 net-next 0/8] net: dsa: netc: add PTP support for NETC switch Jakub Kicinski
2026-09-02 1:43 ` Wei Fang
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=20260901082025.AF94B1F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wei.fang@oss.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