* [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces
2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
@ 2026-11-20 21:21 ` Ahmad Byagowi
2026-11-22 20:10 ` Vadim Fedorenko
2026-11-20 21:21 ` [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
vladimir.oltean
PTP_EXTTS_REQUEST and extts_enable can enable channels without assigning
a PTP_PF_EXTTS pin. ptp_disable_all_events() only visits assigned pins,
so those channels can still generate events after the clock is released.
ptp_ocp exposes six timestamp channels but only four SMA pin descriptors;
the internal GNSS and PHC timestamp sources do not need an SMA assignment.
Disable each advertised external timestamp channel, followed by the
existing PPS disable, after posix_clock_unregister() has removed sysfs
and drained active ioctls. Keep the pin configuration unchanged.
Remove ptp_ocp's preliminary timestamp-disable loop. It runs before the
user interfaces are removed and can race with an enable: the enable sets
pps_req_map, detach clears it and disables the source, then the enable
rearms the source. Both later subscription disables can consequently see
an empty map and skip the hardware shutdown. With shutdown delegated to
the core, requests finish before the final disables and IRQ drains.
Keep the existing resource cleanup for probe failures without a clock.
Do not skip the shared PPS source's register disable when the final
subscription map is empty. An overlapping extts_enable sysfs request and
ioctl can leave an empty map with the source enabled. Once both interfaces
are drained, the core's final disables must still mask and drain the IRQ.
Preserve the shortcut while another PPS or EXTTS subscription remains.
The source-derived ASan/UBSan tests exercise late and in-flight enables,
the early-disable/map race, concurrent sysfs/ioctl requests, active IRQ
draining and shared PPS users.
KUnit tests exercise real PTP registration and unregistration in QEMU
with KASAN and lockdep, using a test callback without physical hardware.
The original teardown issue was reported by the netdev Sashiko AI review.
Codex revised the code, tests and changelog when asked to test Vadim's
cleanup approach, including unassigned channels and shared PPS behavior.
Fixes: a60fc3294a37 ("ptp: rework ptp_clock_unregister() to disable events")
Fixes: 627366c51145 ("ptp: ocp: fix resource freeing order")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Link: https://lore.kernel.org/r/4e42134b-b017-4836-9772-9c1915b16e77@linux.dev
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_chardev.c | 8 +++-----
drivers/ptp/ptp_ocp.c | 17 ++---------------
2 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index f63b45f5ee6a..193e6baf2b47 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -53,11 +53,9 @@ void ptp_disable_all_events(struct ptp_clock *ptp)
unsigned int i;
mutex_lock(&ptp->pincfg_mux);
- /* Disable any pins that may raise EXTTS 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);
+ /* EXTTS requests do not require a pin assignment. */
+ for (i = 0; i < info->n_ext_ts; i++)
+ ptp_disable_pinfunc(info, PTP_PF_EXTTS, i);
/* Disable the PPS event if the driver has PPS support */
if (info->pps) {
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 625a85b2dc7e..b16d36c3305f 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -2559,8 +2559,8 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable)
else
bp->pps_req_map &= ~req;
- /* if no state change, just return */
- if ((!!old_map ^ !!bp->pps_req_map) == 0)
+ /* Skip the register update while a subscription remains. */
+ if (old_map && bp->pps_req_map)
return 0;
}
@@ -5755,19 +5755,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);
- if (bp->pps)
- ptp_ocp_ts_enable(bp->pps, ~0, false);
if (bp->ptp)
ptp_clock_unregister(bp->ptp);
kfree(bp->ptp_info.pin_config);
base-commit: d7f2d9b6c7d0ff0af7d19d889810d35dfe07da90
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces
2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
@ 2026-11-22 20:10 ` Vadim Fedorenko
0 siblings, 0 replies; 6+ messages in thread
From: Vadim Fedorenko @ 2026-11-22 20:10 UTC (permalink / raw)
To: Ahmad Byagowi, netdev
Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
pabeni, richardcochran, rmk+kernel, vladimir.oltean
On 20.11.2026 21:21, Ahmad Byagowi wrote:
> PTP_EXTTS_REQUEST and extts_enable can enable channels without assigning
> a PTP_PF_EXTTS pin. ptp_disable_all_events() only visits assigned pins,
> so those channels can still generate events after the clock is released.
> ptp_ocp exposes six timestamp channels but only four SMA pin descriptors;
> the internal GNSS and PHC timestamp sources do not need an SMA assignment.
>
> Disable each advertised external timestamp channel, followed by the
> existing PPS disable, after posix_clock_unregister() has removed sysfs
> and drained active ioctls. Keep the pin configuration unchanged.
>
> Remove ptp_ocp's preliminary timestamp-disable loop. It runs before the
> user interfaces are removed and can race with an enable: the enable sets
> pps_req_map, detach clears it and disables the source, then the enable
> rearms the source. Both later subscription disables can consequently see
> an empty map and skip the hardware shutdown. With shutdown delegated to
> the core, requests finish before the final disables and IRQ drains.
> Keep the existing resource cleanup for probe failures without a clock.
>
> Do not skip the shared PPS source's register disable when the final
> subscription map is empty. An overlapping extts_enable sysfs request and
> ioctl can leave an empty map with the source enabled. Once both interfaces
> are drained, the core's final disables must still mask and drain the IRQ.
> Preserve the shortcut while another PPS or EXTTS subscription remains.
>
> The source-derived ASan/UBSan tests exercise late and in-flight enables,
> the early-disable/map race, concurrent sysfs/ioctl requests, active IRQ
> draining and shared PPS users.
> KUnit tests exercise real PTP registration and unregistration in QEMU
> with KASAN and lockdep, using a test callback without physical hardware.
>
> The original teardown issue was reported by the netdev Sashiko AI review.
> Codex revised the code, tests and changelog when asked to test Vadim's
> cleanup approach, including unassigned channels and shared PPS behavior.
>
> Fixes: a60fc3294a37 ("ptp: rework ptp_clock_unregister() to disable events")
> Fixes: 627366c51145 ("ptp: ocp: fix resource freeing order")
> Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
> Link: https://lore.kernel.org/r/4e42134b-b017-4836-9772-9c1915b16e77@linux.dev
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
> ---
> drivers/ptp/ptp_chardev.c | 8 +++-----
> drivers/ptp/ptp_ocp.c | 17 ++---------------
> 2 files changed, 5 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index f63b45f5ee6a..193e6baf2b47 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -53,11 +53,9 @@ void ptp_disable_all_events(struct ptp_clock *ptp)
> unsigned int i;
>
> mutex_lock(&ptp->pincfg_mux);
> - /* Disable any pins that may raise EXTTS 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);
> + /* EXTTS requests do not require a pin assignment. */
> + for (i = 0; i < info->n_ext_ts; i++)
> + ptp_disable_pinfunc(info, PTP_PF_EXTTS, i);
I thought we have agreed that time stampers and pins are different beasties.
Still you provide time stamper index to pin function...
--
pw-bot: cr
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations
2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
@ 2026-11-20 21:21 ` Ahmad Byagowi
2026-11-20 21:21 ` [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
2026-11-20 21:21 ` [PATCH net v3 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
3 siblings, 0 replies; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
vladimir.oltean
The selector table index is not the hardware selector value. Passing the
index to the SMA setter can select unrelated signals, or fail on ART.
Use the table value, as the sysfs path already does.
Mask the direction enable bit before the frequency lookup. Otherwise an
enabled, direction-configurable pin has no matching table entry and its
DPLL get or dump fails. Apply both corrections to all board variants.
Reported by the netdev Sashiko AI review and confirmed by code
inspection. Source-derived C regression tests pass with ASan/UBSan;
restoring the faulty selector, mask, disabled-state or DCF value makes
the corresponding regression fail. Tests use stubbed MMIO, not hardware.
The driver object builds on current net with W=1 and KCFLAGS=-Werror. No
physical card was tested.
Codex prepared the fix, tests and changelog from the review and upstream
source, at the request to separate common-driver fixes from WiWi support
and validate removal ordering.
Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_ocp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index b16d36c3305f..95a4df468e79 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -5869,7 +5869,8 @@ static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin,
tbl = bp->sma_op->tbl[sma->mode];
for (i = 0; tbl[i].name; i++)
if (tbl[i].frequency == frequency)
- return ptp_ocp_sma_store_val(bp, i, sma->mode, sma_nr + 1);
+ return ptp_ocp_sma_store_val(bp, tbl[i].value,
+ sma->mode, sma_nr + 1);
return -EINVAL;
}
@@ -5887,6 +5888,7 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
int i;
val = bp->sma_op->get(bp, sma_nr + 1);
+ val &= SMA_SELECT_MASK;
tbl = bp->sma_op->tbl[sma->mode];
for (i = 0; tbl[i].name; i++)
if (val == tbl[i].value) {
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL
2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
2026-11-20 21:21 ` [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
@ 2026-11-20 21:21 ` Ahmad Byagowi
2026-11-20 21:21 ` [PATCH net v3 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
3 siblings, 0 replies; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
vladimir.oltean
Disabling an SMA input clears its mux field. Zero is also the selector
for 10 MHz, so a DPLL read reports 10 MHz while sysfs reports None. The
DPLL core then treats a request to enable 10 MHz as unchanged and skips
the setter, leaving the input disabled.
Substitute SMA_DISABLE for disabled inputs before looking up the
frequency, as the sysfs path already does. The None entry reports zero
Hz and a subsequent 10 MHz request reaches the setter.
Reported by the netdev Sashiko AI review and confirmed by code
inspection. Source-derived C regression tests pass with ASan/UBSan;
restoring the faulty selector, mask, disabled-state or DCF value makes
the corresponding regression fail. Tests use stubbed MMIO, not hardware.
The driver object builds on current net with W=1 and KCFLAGS=-Werror. No
physical card was tested.
Codex prepared the fix, tests and changelog from the review and upstream
source, at the request to separate common-driver fixes from WiWi support
and validate removal ordering.
Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_ocp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 95a4df468e79..653c3b1ca066 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -5889,6 +5889,8 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
val = bp->sma_op->get(bp, sma_nr + 1);
val &= SMA_SELECT_MASK;
+ if (sma->mode == SMA_MODE_IN && sma->disabled)
+ val = SMA_DISABLE;
tbl = bp->sma_op->tbl[sma->mode];
for (i = 0; tbl[i].name; i++)
if (val == tbl[i].value) {
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net v3 4/4] ptp: ocp: correct the DCF output frequency
2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
` (2 preceding siblings ...)
2026-11-20 21:21 ` [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
@ 2026-11-20 21:21 ` Ahmad Byagowi
3 siblings, 0 replies; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
vladimir.oltean
The output selector table uses 77000 Hz for DCF, whereas the input table
and the DPLL supported frequency list use 77500 Hz. A request for the
advertised DCF77 frequency consequently fails on an output, and reading
that output reports a frequency outside its advertised set.
Use 77500 Hz for the DCF output selector as well.
Reported by the netdev Sashiko AI review and confirmed by code
inspection. Source-derived C regression tests pass with ASan/UBSan;
restoring the faulty selector, mask, disabled-state or DCF value makes
the corresponding regression fail. Tests use stubbed MMIO, not hardware.
The driver object builds on current net with W=1 and KCFLAGS=-Werror. No
physical card was tested.
Codex prepared the fix, tests and changelog from the review and upstream
source, at the request to separate common-driver fixes from WiWi support
and validate removal ordering.
Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_ocp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 653c3b1ca066..f4896f980ef5 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -1373,7 +1373,7 @@ static const struct ocp_selector ptp_ocp_sma_out[] = {
{ .name = "GNSS1", .value = 0x0004, .frequency = 1 },
{ .name = "GNSS2", .value = 0x0008, .frequency = 1 },
{ .name = "IRIG", .value = 0x0010, .frequency = 10000 },
- { .name = "DCF", .value = 0x0020, .frequency = 77000 },
+ { .name = "DCF", .value = 0x0020, .frequency = 77500 },
{ .name = "GEN1", .value = 0x0040 },
{ .name = "GEN2", .value = 0x0080 },
{ .name = "GEN3", .value = 0x0100 },
^ permalink raw reply related [flat|nested] 6+ messages in thread