ptp: serialize requests and stop unassigned timestamps
Subsystems (3)
v6 cover ptp: serialize requests and stop unassigned timestamps
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
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v6 1/2 ptp: serialize sysfs enable requests with ioctl paths
From: ahmadexp <[email protected]>
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.
--- drivers/ptp/ptp_sysfs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/ptp/ptp_sysfs.c +9 -0
@@ -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;
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH v6 2/2 ptp: disable unassigned timestamp channels on unregister
In reply to Ahmad ByagowiFrom: ahmadexp <[email protected]>
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.
--- drivers/ptp/ptp_chardev.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/ptp/ptp_chardev.c +9 -5
@@ -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) {
Signature · 1 line
2.54.0 (Apple Git-157)