* [PATCH net v6 0/2] ptp: serialize requests and stop unassigned timestamps
@ 2026-11-26 16:41 Ahmad Byagowi
2026-11-26 16:41 ` [PATCH net v6 1/2] ptp: serialize sysfs enable requests with ioctl paths Ahmad Byagowi
2026-11-26 16:41 ` [PATCH net v6 2/2] ptp: disable unassigned timestamp channels on unregister Ahmad Byagowi
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:41 UTC (permalink / raw)
To: netdev
Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
vadim.fedorenko, andrew+netdev, arnd, john.stultz, rmk+kernel
This PTP core series serializes the sysfs enable callbacks with the ioctl
paths, then disables every advertised external timestamp channel during
clock unregister. The generic teardown patch changes only the PTP core; it
does not modify ptp_ocp or another clock driver.
This split follows Vadim Fedorenko's review request to keep PTP core/PHC
changes separate from driver-specific fixes. The dependent driver series is
prepared separately and must follow this core series.
Validation: strict x86_64 object build for ptp_chardev.o, ptp_sysfs.o,
ptp_ocp.o and sja1105_ptp.o with W=1 KCFLAGS=-Werror; source-derived
teardown tests for all six EXTTS channels, unassigned/zero pins, interface
removal, callback serialization and IRQ draining. Tests use stubbed hardware
operations; no physical card or switch was tested. No KUnit run was done for
this revision.
A coding assistant helped identify the gaps, develop the fixes and regression
tests, and prepare changelog text.
Ahmad Byagowi (2):
ptp: serialize sysfs enable requests with ioctl paths
ptp: disable unassigned timestamp channels on unregister
drivers/ptp/ptp_chardev.c | 14 +++++++++-----
drivers/ptp/ptp_sysfs.c | 9 +++++++++
2 files changed, 18 insertions(+), 5 deletions(-)
base-commit: 4392bb809812ac79449cd0cf1f5e00469ee102d1
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net v6 1/2] ptp: serialize sysfs enable requests with ioctl paths
2026-11-26 16:41 [PATCH net v6 0/2] ptp: serialize requests and stop unassigned timestamps Ahmad Byagowi
@ 2026-11-26 16:41 ` Ahmad Byagowi
2026-11-26 16:41 ` [PATCH net v6 2/2] ptp: disable unassigned timestamp channels on unregister Ahmad Byagowi
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:41 UTC (permalink / raw)
To: netdev
Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
vadim.fedorenko, andrew+netdev, arnd, john.stultz, rmk+kernel
From: ahmadexp <ahmadexp@gmail.com>
EXTTS, PPS and period sysfs stores invoke the clock driver callback without the pincfg_mux mutex. The ioctl paths and pin configuration changes use that mutex, so sysfs can race with those operations and with other sysfs requests.
Take pincfg_mux around each enable callback. Keep validation and permission checks outside the critical section, propagate callback failures, and return -ERESTARTSYS when mutex acquisition is interrupted. The mutex is required because disable callbacks may sleep while draining an IRQ.
A coding assistant helped identify the missing serialization, develop the fix and regression tests, and prepare this changelog. The source-derived tests exercise the actual callbacks with controlled scheduling; KUnit coverage uses the actual stores under lock contention.
Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.")
Link: https://lore.kernel.org/r/179548551283.3135.17206659598806657887@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_sysfs.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
index 8e0e0aa09981..90fdddc1e6a7 100644
--- a/drivers/ptp/ptp_sysfs.c
+++ b/drivers/ptp/ptp_sysfs.c
@@ -60,7 +60,10 @@ static ssize_t extts_enable_store(struct device *dev,
if (req.extts.index >= ops->n_ext_ts)
goto out;
+ if (mutex_lock_interruptible(&ptp->pincfg_mux))
+ return -ERESTARTSYS;
err = ops->enable(ops, &req, enable ? 1 : 0);
+ mutex_unlock(&ptp->pincfg_mux);
if (err)
goto out;
@@ -130,7 +133,10 @@ static ssize_t period_store(struct device *dev,
goto out;
enable = req.perout.period.sec || req.perout.period.nsec;
+ if (mutex_lock_interruptible(&ptp->pincfg_mux))
+ return -ERESTARTSYS;
err = ops->enable(ops, &req, enable);
+ mutex_unlock(&ptp->pincfg_mux);
if (err)
goto out;
@@ -157,7 +163,10 @@ static ssize_t pps_enable_store(struct device *dev,
if (cnt != 1)
goto out;
+ if (mutex_lock_interruptible(&ptp->pincfg_mux))
+ return -ERESTARTSYS;
err = ops->enable(ops, &req, enable ? 1 : 0);
+ mutex_unlock(&ptp->pincfg_mux);
if (err)
goto out;
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH net v6 2/2] ptp: disable unassigned timestamp channels on unregister
2026-11-26 16:41 [PATCH net v6 0/2] ptp: serialize requests and stop unassigned timestamps Ahmad Byagowi
2026-11-26 16:41 ` [PATCH net v6 1/2] ptp: serialize sysfs enable requests with ioctl paths Ahmad Byagowi
@ 2026-11-26 16:41 ` Ahmad Byagowi
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:41 UTC (permalink / raw)
To: netdev
Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
vadim.fedorenko, andrew+netdev, arnd, john.stultz, rmk+kernel
From: ahmadexp <ahmadexp@gmail.com>
PTP_EXTTS_REQUEST can enable a channel without assigning PTP_PF_EXTTS to a pin. ptp_disable_all_events() currently walks only configured pins, so unassigned channels can remain active after the clock is unregistered.
After removing the user interfaces and draining active operations, issue a direct PTP_CLK_REQ_EXTTS disable for every advertised external timestamp channel. Keep pin assignments unchanged and retain the existing PPS shutdown. This is a PTP core change and does not modify any clock driver.
A coding assistant helped identify the unassigned-channel teardown gap, develop the core fix and regression tests, and prepare this changelog. The regression harness exercises the actual cleanup path with controlled clock callbacks; no physical card was tested.
Fixes: a60fc3294a37 ("ptp: rework ptp_clock_unregister() to disable events")
Fixes: 627366c51145 ("ptp: ocp: fix resource freeing order")
Link: https://lore.kernel.org/r/179548551283.3135.17206659598806657887@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_chardev.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index f63b45f5ee6a..5835c01cddb4 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -53,11 +53,15 @@ 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++) {
+ struct ptp_clock_request req = {
+ .type = PTP_CLK_REQ_EXTTS,
+ .extts.index = i,
+ };
+
+ info->enable(info, &req, 0);
+ }
/* Disable the PPS event if the driver has PPS support */
if (info->pps) {
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-26 16:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 16:41 [PATCH net v6 0/2] ptp: serialize requests and stop unassigned timestamps Ahmad Byagowi
2026-11-26 16:41 ` [PATCH net v6 1/2] ptp: serialize sysfs enable requests with ioctl paths Ahmad Byagowi
2026-11-26 16:41 ` [PATCH net v6 2/2] ptp: disable unassigned timestamp channels on unregister Ahmad Byagowi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox