Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: ahmadexp@gmail.com
Cc: netdev@vger.kernel.org, richardcochran@gmail.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, vladimir.oltean@nxp.com,
	vadim.fedorenko@linux.dev, andrew@lunn.ch,
	linux-kernel@vger.kernel.org, arkadiusz.kubalewski@intel.com,
	jiri@resnulli.us, jonathan.lemon@gmail.com
Subject: Re: [PATCH net v6 8/8] ptp: ocp: defer timestamp shutdown to clock unregister
Date: Fri, 27 Nov 2026 16:48:08 +0000	[thread overview]
Message-ID: <179579808820.3135.11076556680747243483@kernel.org> (raw)
In-Reply-To: <20261126-timecard-driver-v6-8-ahmadexp@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 1 · High: 1 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Critical] In ptp_ocp_detach() (drivers/ptp/ptp_ocp.c), the patch
  removes the explicit ptp_ocp_ts_enable(bp->ts0..ts4, 0, false) and…
- [High] Removing ptp_ocp_ts_enable(bp->pps, ~0, false) from
  ptp_ocp_detach() leaves the core's PTP_CLK_REQ_PPS request as the only…
- [Medium] The commit is not self-contained but has a Fixes: tag for
  627366c51145 ("ptp: ocp: fix resource freeing order").

--

ptp: ocp: defer timestamp shutdown to clock unregister

This patch removes the explicit ptp_ocp_ts_enable() calls for ts0..ts4 and
pps from ptp_ocp_detach(). It relies on the PTP core unregister path to
disable the timestamp channels once the user interfaces are gone. The
commit message says it depends on a separate PTP core teardown series.

Link: https://lore.kernel.org/r/179548551283.3135.17206659598806657887@kernel.org

> This driver patch depends on the separate PTP core teardown series.

[ ... ]

> Fixes: 627366c51145 ("ptp: ocp: fix resource freeing order")

[Severity: Medium]
Which series does this refer to? The only Link: tag points to a single
lore message, not a patch series. There is also no commit ID or stable
dependency note for the prerequisite.

In this tree, ptp_disable_all_events() and ptp_clock_unregister() do not
seem to contain the core change this patch relies on.

The Fixes: target 627366c51145 is the commit that added the early-disable
block being removed here. Because of the Fixes: tag, could stable tooling
pick up this patch without the core series? That would bring the
timestamp IRQ regression described below into stable kernels.

Could the prerequisite be named explicitly, or this patch be sent as part
of the core series?

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 0405188951768..27cf3ab3327c4 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -5768,19 +5768,6 @@ ptp_ocp_detach(struct ptp_ocp *bp)
>  	ptp_ocp_detach_sysfs(bp);
>  	ptp_ocp_attr_group_del(bp);
>  	timer_delete_sync(&bp->watchdog);
> -	/* Disable interrupts on all timestampers */
> -	if (bp->ts0)
> -		ptp_ocp_ts_enable(bp->ts0, 0, false);
> -	if (bp->ts1)
> -		ptp_ocp_ts_enable(bp->ts1, 0, false);
> -	if (bp->ts2)
> -		ptp_ocp_ts_enable(bp->ts2, 0, false);
> -	if (bp->ts3)
> -		ptp_ocp_ts_enable(bp->ts3, 0, false);
> -	if (bp->ts4)
> -		ptp_ocp_ts_enable(bp->ts4, 0, false);

[Severity: Critical]
Does ptp_disable_all_events() in this tree actually disable these
channels? It only handles pins whose function is PTP_PF_EXTTS, plus one
PPS request:

drivers/ptp/ptp_chardev.c:ptp_disable_all_events() {
    ...
	for (i = 0; i < info->n_pins; i++)
		if (info->pin_config[i].func == PTP_PF_EXTTS)
			ptp_disable_pinfunc(info, info->pin_config[i].func,
					    info->pin_config[i].chan);

	/* Disable the PPS event if the driver has PPS support */
	if (info->pps) {
		struct ptp_clock_request req = { .type = PTP_CLK_REQ_PPS };
		info->enable(info, &req, 0);
	}
    ...
}

ptp_ocp has n_ext_ts = 6 but only 4 pins. ptp_ocp_set_pins() allocates
the pins zeroed, so by default they are all PTP_PF_NONE.

EXTTS channels can be enabled by index with no pin assigned. Both
ptp_extts_request() (PTP_EXTTS_REQUEST) and extts_enable_store() do this,
and nothing disables the channel when the fd is closed.

For bp->pps, the core request becomes
ptp_ocp_ts_enable(bp->pps, OCP_REQ_PPS, false). If OCP_REQ_TIMESTAMP
(EXTTS index 5) is also set, pps_req_map stays non-zero. The "no state
change" shortcut then returns early and the PPS/TS5 timestamper stays
armed.

In all of these cases the interrupt is still unmasked and requested when
ptp_clock_unregister() does its final put_device(). That put runs
ptp_clock_release():

drivers/ptp/ptp_clock.c:ptp_clock_release() {
    ...
	bitmap_free(tsevq->mask);
	kfree(tsevq);
	debugfs_remove(ptp->debugfs_root);
	xa_erase(&ptp_clocks_map, ptp->index);
	kfree(ptp);
}

bp->ptp is not cleared. The IRQ is only disabled and freed later, one
source at a time, in ptp_ocp_unregister_ext():

	ext->info->enable(ext, ~0, false);
	pci_free_irq(ext->bp->pdev, ext->irq_vec, ext);

Can a timestamp interrupt in that window write to freed memory?

ptp_ocp_ts_irq()
    ptp_clock_event(ext->bp->ptp, &ev)     /* PTP_CLOCK_EXTTS */
        spin_lock_irqsave(&ptp->tsevqs_lock, flags);
        list_for_each_entry(tsevq, &ptp->tsevqs, qlist)
            enqueue_external_timestamp(tsevq, event);

One way to hit this: enable a channel with "echo '0 1' > extts_enable",
feed a 1PPS signal on the input, then unbind or remove the device.

This seems to reopen the use-after-free that 627366c51145 ("ptp: ocp: fix
resource freeing order") closed.

> -	if (bp->pps)
> -		ptp_ocp_ts_enable(bp->pps, ~0, false);
>  	if (bp->ptp)
>  		ptp_clock_unregister(bp->ptp);

[Severity: High]
With this call gone, is an in-flight PPS interrupt still drained before
pps_unregister_source()?

The only teardown disable left for the PPS event is the core's
PTP_CLK_REQ_PPS request. It goes through
ptp_ocp_enable()->ptp_ocp_ts_enable(bp->pps, OCP_REQ_PPS, false).

If OCP_REQ_TIMESTAMP is also set in pps_req_map, the map stays non-zero.
The function then returns before the intr_mask write and before
synchronize_irq():

drivers/ptp/ptp_ocp.c:ptp_ocp_ts_enable() {
    ...
		/* if no state change, just return */
		if ((!!old_map ^ !!bp->pps_req_map) == 0)
			return 0;
    ...
}

A ptp_ocp_ts_irq() already running on another CPU may have seen
OCP_REQ_PPS set. pps_req_map is a plain field, written under pincfg_mux
and read without a lock in hardirq context:

drivers/ptp/ptp_ocp.c:ptp_ocp_ts_irq() {
    ...
		if (ext->bp->pps_req_map & OCP_REQ_PPS) {
			ev.type = PTP_CLOCK_PPS;
			ptp_clock_event(ext->bp->ptp, &ev);
		}
    ...
}

Meanwhile ptp_clock_unregister() continues:

	ptp_disable_all_events(ptp);
	...
	if (ptp->pps_source)
		pps_unregister_source(ptp->pps_source);

Could pps_event(ptp->pps_source, ...) still be running in that handler
when pps_unregister_source() tears down and frees the pps_device?

Before this patch, the req = ~0 call always set pps_req_map to 0. The
source was masked and synchronize_irq() ran before ptp_clock_unregister().

>  	kfree(bp->ptp_info.pin_config);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com

      reply	other threads:[~2026-11-27 16:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
2026-11-26 16:42 ` [PATCH net v6 1/8] net: dsa: sja1105: keep pin function on EXTTS disable Ahmad Byagowi
2026-11-27 16:47   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable Ahmad Byagowi
2026-11-27 16:47   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko
2026-11-27 16:53   ` Olech, Milena
2026-11-26 16:42 ` [PATCH net v6 4/8] ptp: ocp: restore disabled SMA inputs when binding Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 5/8] ptp: ocp: report disabled SMA inputs as zero Hz Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 6/8] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 7/8] ptp: ocp: match ART DPLL frequencies to selectors Ahmad Byagowi
2026-11-26 16:42 ` [PATCH net v6 8/8] ptp: ocp: defer timestamp shutdown to clock unregister Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko [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=179579808820.3135.11076556680747243483@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=ahmadexp@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=jonathan.lemon@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=vladimir.oltean@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